Difference between revisions of "Legacy:RequireSystemScript"
From Spherical
(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 | + | {{Usage|func=RequireSystemScript|params=filename}} |
− | * ''' | + | * '''filename''' string. The name of the system script to be executed. |
− | |||
− | |||
==Examples== | ==Examples== | ||
− | ( | + | <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== | ||
− | + | See [[API:EvaluateSystemScript|EvaluateSystemScript]]and [[API:RequireScript|RequireScript]]for more details. | |
==See also== | ==See also== | ||
− | * | + | * [[API:EvaluateScript|EvaluateScript]](filename) |
− | * | + | * [[API:EvaluateSystemScript|EvaluateSystemScript]](filename) |
− | * | + | * [[API:RequireScript|RequireScript]](filename) |
− | * | + | * [[: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).
Contents
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
- EvaluateScript(filename)
- EvaluateSystemScript(filename)
- RequireScript(filename)
- Scripts category