SetUpdateScript

From Spheriki

Jump to: navigation, search

Sets a map update script.


Contents

Usage

SetUpdateScript(script);
  • script string. Contains the JavaScript code to update for each map update.


Examples

To increase a score variable at each moment by 1:

SetUpdateScript("++score;");

Or

// In a file
var score = 0;
function updateScript()
{
  ++score;
}
// Before you run the map engine
SetUpdateScript("updateScript();");


Notes

  • The script parameter needs to be a string, rather than regular JavaScript code. See the example.
  • The difference between an update script and a render script: update scripts will always run at the frame rate you give, while render scripts will only run when Sphere's map engine draws to the screen. For every rendered frame, the update script will run one or more times (to maintain regular speed), then the map will be drawn, and then the render script. Therefore, the update script is more resilient to potential slowdown/speedup.


See also

Personal tools