Difference between revisions of "Legacy:RequireScript"

From Spherical
Jump to: navigation, search
(created from http://web.archive.org/web/20120327155800/http://spheredev.org/wiki/RequireScript)
 
(filled)
 
Line 1: Line 1:
 
+
The RequireScript(filename) command will do the same thing as the [[API:EvaluateScript|EvaluateScript]](filename) command, except it will only allow each filename to be loaded once. The purpose of this is to prevent a particular script from being loaded multiple times, wasting resources and possibly causing other problems, but still giving the programmer the option of using a script which might or might not have been previously loaded. In particular, this is useful if there are multiple programmers working on different systems for a game, and will need to combine them into the final project afterwards, or if the programmer is making generic scripts that will be useful in other games.
 
 
The RequireScript(filename) command will do the same thing as the EvaluateScript(filename) command, except it will only allow each filename to be loaded once. The purpose of this is to prevent a particular script from being loaded multiple times, wasting resources and possibly causing other problems, but still giving the programmer the option of using a script which might or might not have been previously loaded. In particular, this is useful if there are multiple programmers working on different systems for a game, and will need to combine them into the final project afterwards, or if the programmer is making generic scripts that will be useful in other games.
 
  
 
__TOC__
 
__TOC__
  
 
==Usage==
 
==Usage==
{{Usage|returns={{{returns}}}|object={{{object}}}|func=RequireScript|params=filename}}
+
{{Usage|func=RequireScript|params=filename}}
  
* '''param1''' type. param1 description
+
* '''filename''' string. The name of the file containing the code to be executed.
* '''param2''' type. param2 description
 
* '''paramN''' type. paramN description
 
  
 
==Examples==
 
==Examples==
(examples with syntaxhighlighted code)
+
Note that the following example is fictional; it's likely you don't have either JS file that are used in the example, unless you specifically made them.
 +
 
 +
<syntaxhighlight>
 +
RequireScript("intro.js");
 +
RequireScript("game_menu.js");
 +
 
 +
function game()
 +
{
 +
  //A function contained in "intro.js"
 +
  Intro();
 +
  //A function contained in "game_menu.js"
 +
  GameMenu();
 +
}
 +
</syntaxhighlight>
  
 
==Notes==
 
==Notes==
(notes)
+
See [[API:EvaluateScript|EvaluateScript]] for more details.
  
 
==See also==
 
==See also==
* see also
+
* [[API:EvaluateScript|EvaluateScript]](filename)
* see also
+
* [[API:EvaluateSystemScript|EvaluateSystemScript]](filename)
* see also
+
* [[API:RequireSystemScript|RequireSystemScript]](filename)
* etc
+
 
 +
{{API:Script/navbox}}

Latest revision as of 02:21, 2 June 2013

The RequireScript(filename) command will do the same thing as the EvaluateScript(filename) command, except it will only allow each filename to be loaded once. The purpose of this is to prevent a particular script from being loaded multiple times, wasting resources and possibly causing other problems, but still giving the programmer the option of using a script which might or might not have been previously loaded. In particular, this is useful if there are multiple programmers working on different systems for a game, and will need to combine them into the final project afterwards, or if the programmer is making generic scripts that will be useful in other games.

Usage

RequireScript(filename);


  • filename string. The name of the file containing the code to be executed.

Examples

Note that the following example is fictional; it's likely you don't have either JS file that are used in the example, unless you specifically made them.

RequireScript("intro.js");
RequireScript("game_menu.js");

function game()
{
  //A function contained in "intro.js"
  Intro();
  //A function contained in "game_menu.js"
  GameMenu();
}

Notes

See EvaluateScript for more details.

See also

API:Script/navbox