Runs on the Ancient Brain system have the following global variable defined:


 AB;               // instance of class ABClass - basic functionality for Ancient Brain 

AB contains the following data and functions. Default values shown.

Global settings


AB.clockTick       = 100;    

	// Speed of run: Step every n milliseconds.  
AB.maxSteps        = 1000;    

	// Length of run: Maximum length of run in steps.  

AB.screenshotStep  = 50;   
	// For automatic generation of World images.
	// Take screenshot on this step. (All resources should have finished loading.)  

AB.drawRunControls = true;			

	// Add run controls (Run/Step/Pause) to the run window  

The run

AB.step;               // the step of the run   

AB.abortRun = false;   // set this to true anytime to end the run   

Delayed run, loading screen, splash screen

We often want to delay the start of the run until resources are loaded, or until the user has clicked on a splash screen. Here is how to do it.

A loading screen vanishes automatically when resources load. A splash screen needs user interaction to dismiss.


AB.runReady = true;                  // Start the run loop immediately   
AB.loadingScreen();                  // draw standard loading screen   
AB.removeLoading();                  // remove loading screen 

AB.newSplash();                      // draw standard splash screen  
AB.newSplash ( html );               // draw standard splash screen with this html as the message 
AB.removeSplash();                   // remove splash screen 

Run header


AB.showRunHeader();     // show run header (in case does not show automatically)
AB.hideRunHeader();     // hide run header  

AB.headerLHS();         // put run header on LHS   
AB.headerRHS();         // put run header on RHS 

AB.headerWidth ( w );   // Give run header a fixed width  
  // Useful because writing changing info to variable width header 
  // can lead to header "flicker" as it keeps changing width  

AB.msg ( html, n );     // Write a message (html) to a numbered location in the run header  
AB.msg ( html );        // Write message to location 1

AB.newDiv ( id );       // Create new div on page with this id (can then set style, content) 

Run functions


AB.onDesktop();                      // return if running on desktop
AB.onMobile();                       // return if running on mobile 

AB.backgroundMusic ( musicfile );    // play background music, draw buttons, return audio object 
AB.standardAudioButtons ( audio );   // draw standard play/pause buttons for this audio 
AB.audioIsPlaying ( audio );         // return if this audio is currently playing 

AB.isScreenshotRun();                // is this a run that generates a screenshot 

Launch buttons

These functions allow you embed in your run a "launch button" to run Worlds, like the launch buttons used on the main Ancient Brain site. The "button" is a small World image, hover makes it zoom, and click starts a run.

These functions return the HTML code needed to make the "button". You then put this HTML code somewhere in the run page.


AB.launchWorld ( worldid, worldtitle );                          // returns HTML string 
AB.launchWorldMind ( worldid, worldtitle, mindid, mindtitle );   // returns HTML string

Save and restore data

If you run "logged in" you can save and restore data to and from the server.


AB.runloggedin;                 // Boolean. Are we running logged in.  
AB.myuserid;                    // The userid of the run, if running logged in.  

AB.saveData ( object );             
    // Save this object to the server for this user for this World.

AB.queryDataExists ( function ( boolean ) { ... } );  
    // Query if data exists on the server for this user for this World.
    // When it returns, it calls the callback function with boolean (exists or not).

AB.restoreData ( function ( object ) { ... } );      
    // Recover the data saved for this user for this World.
    // When it returns, it calls the callback function with the object. 
AB.getAllData ( function ( array ) { ... } );    
    // Get all data saved for all users for this World.
    // When it returns, it calls the callback function with an array. 
    // This is an array of items ( userid, username, object ). 


Generic functions


AB.randomFloatAtoB ( A, B );         // return random float between A and B
AB.randomIntAtoB ( A, B );           // return random int between A and B

AB.randomEventProb ( p );            // return boolean should event of this probability happen now
AB.randomBoolean();                  // return random true or false 
AB.randomPick ( a, b );              // return a or b randomly 
AB.randomPick3 ( a, b, c );          // return a, b or c randomly 
AB.randomElementOfArray ( array );   // return random element of this array 

AB.distance2D ( x1, y1, x2, y2 );    // return distance between two points on 2D plane