Ancient Brain
  
Drag the background!
 

Step 7. Program structure

This program uses the following structure to define what code runs once at startup, and what code runs every time step:

// Can define global variables and constants up here, outside both functions  
  
AB.world.newRun = function() 
{
	// Instructions to be executed once, at start of run 
};

AB.world.nextStep = function() 
{
	// Instructions to be executed every time step 
};
Note the chain brackets. These define the start and end of blocks of code. In the World so far, we did not define any "AB.world.nextStep" because we did not have any code to execute on every step. For full reference on this structure, see the World and Mind docs.

We will now add some new code at certain locations within the structure.

The background is a program, showing the JavaScript graphics used on this site.
The globes light up when you log in. Drag the background to move the camera.
Customise background:  
Font:

Website © Ancient Brain 2025.
Users retain ownership of user content.

Platforms      Stats      The name      Terms and conditions

Call for partners      Contact

Call for partners!
Ancient Brain is looking for a partner to co-write a JavaScript coding book for schools, to be used worldwide. This would be a course for students in learning to code from scratch. The book and course will be integrated into the Ancient Brain site. This is an opportunity for someone looking to develop a course and textbook to partner with a site to promote it. Read more.