Legacy:RequireSystemScript

From Spherical
Revision as of 00:53, 2 June 2013 by Apollolux (talk | contribs) (Cleanup)
Jump to: navigation, search

The RequireSystemScript(filename) command will do the same thing as the EvaluateSystemScript(filename) command, except it will only allow each system script to be loaded once. The purpose of this is the same as that of RequireScript, but works for system scripts instead (see EvaluateSystemScript).

Usage

RequireSystemScript(filename);


  • filename string. The name of the system script to be executed.

Examples

RequireSystemScript("time.js");

function game()
{
  var font = GetSystemFont();
  font.drawText(0,0, "This line is shown first");
  FlipScreen();
  Delay(2000);
  font.drawText(0,0, "Then this line is shown 2 seconds later.");
  FlipScreen();
  GetKey();
}

In this example, Delay(2000) is a piece of code that is found in the system script time.js, so when using it in this script it will look up the function in the system script time.js.

RequireSystemScript("menu.js");

function game()
{
  // This shows a basic menu
  var menu = new Menu();

  menu.addItem("Start New Game",    NewGame);
  menu.addItem("Exit",        Exit);
  menu.execute(250, 400, 140, 30); 
}

Menu() is an object that can be found in the system script menu.js. All of its properties are taken over when creating a new Menu() somewhere.

Notes

See EvaluateSystemScriptand RequireScriptfor more details.

See also