How to write a World

The basic choice is what API to use, and whether your World is controlled by a Mind or not.




APIs

Each World runs using a particular API. The API typically provides graphics JS libraries plus Ancient Brain libraries. Each Mind uses the API of its World.

New APIs will be added in the future. (For example, ones based on new graphics libraries.) All old APIs will be kept, so that runs always work.

The home page for each World links to the API it uses. Authors should examine the API page to see how to write for it.

As far as possible, APIs are designed so that most parts are optional. Authors can omit parts and, as far as possible, the program will still run.

See List of APIs currently installed.




Generate a new blank World

Most Worlds will probably be created by taking an existing working World and cloning it and then editing it.

If you want to start with a blank page, use this link:


Generate a new blank World





World screenshot

There is an image or screenshot to represent each World.

If you are the owner of a World:




Upload support files

You can upload support files to use in your World:

You upload files on your uploads page (see link on your home page). See for example the uploads page for the user Starter user.

Reference your uploads in your code using an absolute path like: '/uploads/user/file'

You can reference other people's uploads. (Though note there is a risk they will delete them.)





Audio autoplay on web pages

These Worlds are web pages. Audio automatically playing on web pages can be annoying. As a result, in many browsers (notably Chrome and mobile browsers) audio will not automatically play but requires user interaction to start it. The Starter Worlds that have background music have "play" and "pause" buttons for manual control if the music does not start.

A better solution is a "splash screen" to get user interaction at the start of the run, and start background music, and set up audio events that can be randomly triggered by the JS later without further user interaction. See Audio for Web games.

Here are some sample Worlds using user interaction (on a splash screen) to start background music and set up audio events for later.


Bouncy Balls
329 runs ♦ 2 likes
By Starter user  
Created: 1 Oct 2017
Modified: 14 Nov 2019
Demo of Physics API. Balls bounce under gravity and collide in low friction world. Splash screen...
Collision World
753 runs ♦ 2 likes
By Starter user  
Created: 21 Sep 2017
Modified: 14 Nov 2019
Demo of Physics API. Blocks fall under gravity and collide. Can modify gravity, friction, etc. S...
Zombie Death Baby
423 runs ♦ 0 likes
By Starter user  
Created: 11 Jun 2018
Modified: 14 Nov 2019
How to make a fun touch game for mobile. Touch drag and tap objects. Mouse drag and click object...
Castle World
484 runs ♦ 3 likes
By Starter user  
Created: 11 Nov 2016
Modified: 14 Nov 2019
Demo of how to insert 3d model into World. Mind-controlled agent, actively-pursuing enemy. Splas...



How to make Chrome autoplay audio

You can change Chrome to autoplay audio:
  1. Type in address:
     chrome://flags/ 
  2. Search for "Autoplay policy".
  3. Select "No user gesture is required".
  4. Restart Chrome.
Chrome may later reset this flag, and you may have to do this again!




Human interaction with World - keyboard

On the desktop, you can allow the human interact with the World through the keyboard.

Here is a sample World that reads keyboard input using keycodes. Run on desktop to see.


Touch World
301 runs ♦ 1 like
By Starter user  
Created: 6 Jan 2018
Modified: 14 Nov 2019
How to override default touch handling. Mobile: Touch drag moves agent, touch pinch zooms camera...
  
  

Human interaction with World - mouse

On the desktop, in our normal Three.js based APIs, mouse drag and scroll controls the camera.

If you want to use the mouse to do something else, you can override the mouse camera control, and capture Mouse events yourself in your JavaScript.

Here is a sample World showing Mouse drag for moving an agent around the World, and mouse click on an object to change it. Run on desktop to see.


Zombie Death Baby
423 runs ♦ 0 likes
By Starter user  
Created: 11 Jun 2018
Modified: 14 Nov 2019
How to make a fun touch game for mobile. Touch drag and tap objects. Mouse drag and click object...
  
  

Human interaction with World - touch screen

On mobile and tablet, in our normal Three.js based APIs, touch drag and pinch controls the camera.

If you want to use touch to do something else, you can override the touch camera control, and capture Touch events yourself in your JavaScript.

Below are sample Worlds showing touch drag for moving an agent around the World, and touch tap on an object to change it. Run these on mobile to see.


Touch World
301 runs ♦ 1 like
By Starter user  
Created: 6 Jan 2018
Modified: 14 Nov 2019
How to override default touch handling. Mobile: Touch drag moves agent, touch pinch zooms camera...
Zombie Death Baby
423 runs ♦ 0 likes
By Starter user  
Created: 11 Jun 2018
Modified: 14 Nov 2019
How to make a fun touch game for mobile. Touch drag and tap objects. Mouse drag and click object...
  
  

Writing instructions, help and output

For your World to write output to the screen (e.g. game instructions, help, details about the run) we suggest using these functions:

You can also write instructions for authors at the top of the JS code. Only authors will look at this.



The "tweaker's box"

When writing a World, you might consider users who will want to edit and customise your World. Some will have limited programming ability.

It is recommended (though not enforced) that you mark out a section at the top of the code containing the things that can be easily changed in your World by a non-programmer. We call this the "tweaker's box". What is below the "tweaker's box" will need programming skills to change.

For examples of the "tweaker's box" concept, see many of the Starter Worlds. See a JS code search of all Worlds for tweaker's box.