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.runReady = true;      // Are we ready to go into the run loop? 

   // This is useful when a World loads resources from files.
   // We often prefer to load all resources first, before the run loop starts.
   // In AB.world.newRun(), set AB.runReady = false, and then load resources.
   // When load finished, set AB.runReady = true and run loop will start.
   // Also useful if there is a splash screen. 
   // Pause the run loop until the user dismisses the splash screen.
AB.step;               // the step of the run   

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

Run header, loading screen, splash screen

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

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 

AB.showRunHeader();     // show run header (in case does not show automatically)
AB.headerLHS();         // put run header on LHS   
AB.headerRHS();         // put run header on RHS 

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

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. See an example here.


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 ). 

Here is an example of a World that uses these functions.

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.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