Difference between revisions of "Legacy:RequireSystemScript"

From Spherical
Jump to: navigation, search
(created from http://web.archive.org/web/20120828095147/http://www.spheredev.org/wiki/RequireSystemScript)
 
(Cleanup)
Line 1: Line 1:
 
+
The RequireSystemScript(filename) command will do the same thing as the [[API:EvaluateSystemScript|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 [[API:RequireScript|RequireScript]], but works for system scripts instead (see [[API:EvaluateSystemScript|EvaluateSystemScript]]).
 
 
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).
 
  
 
__TOC__
 
__TOC__
  
 
==Usage==
 
==Usage==
{{Usage|returns=|object=|func=RequireSystemScript|params=filename}}
+
{{Usage|func=RequireSystemScript|params=filename}}
  
* '''param1''' type. param1 description
+
* '''filename''' string. The name of the system script to be executed.
* '''param2''' type. param2 description
 
* '''paramN''' type. paramN description
 
  
 
==Examples==
 
==Examples==
(examples with syntaxhighlighted code)
+
<syntaxhighlight>
 +
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();
 +
}
 +
</syntaxhighlight>
 +
 
 +
In this example, <code>Delay(2000)</code> is a piece of code that is found in the [[Script:time.js|system script ''time.js'']], so when using it in this script it will look up the function in the system script time.js.
 +
 
 +
<syntaxhighlight>
 +
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);
 +
}
 +
</syntaxhighlight>
 +
 
 +
<code>Menu()</code> is an object that can be found in the [[Script:menu.js|system script ''menu.js'']]. All of its properties are taken over when creating a new Menu() somewhere.
  
 
==Notes==
 
==Notes==
(notes)
+
See [[API:EvaluateSystemScript|EvaluateSystemScript]]and [[API:RequireScript|RequireScript]]for more details.
  
 
==See also==
 
==See also==
* see also
+
* [[API:EvaluateScript|EvaluateScript]](filename)
* see also
+
* [[API:EvaluateSystemScript|EvaluateSystemScript]](filename)
* see also
+
* [[API:RequireScript|RequireScript]](filename)
* etc
+
* [[:Category:Scripts|Scripts]] category

Revision as of 00:53, 2 June 2013

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