ExecuteGame
From Spheriki
Runs an installed Sphere game within the sphere/games/ directory.
Contents |
[edit]
Usage
ExecuteGame(directory);
- directory is a string which is the name of the directory of the game within
sphere/games/to be run.
[edit]
Examples
// Run a game given the name of its directory. // DO NOT provide the name of the directory THIS game resides in! var dir = "insert_dir_name_here"; ExecuteGame(dir);
Runs a game, given its directory name, which you can look up in the sphere/games/ directory.
// Run a random game.
// To run again, go into sphere/games/<dir>/save/
// and delete the file "loopstop.txt".
var f = OpenFile("loopstop.txt");
var stop_loop = f.read("stop_infinite_loop", false);
if (stop_loop)
{
f.close();
Exit();
}
else
{
f.write("stop_infinite_loop", true);
f.flush();
f.close();
var games = GetGameList();
ExecuteGame(games[Math.random() * games.length].directory);
}
The important lines are the last two. Note the symbiosis between GetGameList() and ExecuteGame(). The argument taken by ExecuteGame() corresponds with the Game object property directory.
[edit]
Notes
- This function exits the first game (the one in which the ExecuteGame() call occurred) and loads the one specified by the
directoryargument. When the second game ends, the first game is reloaded and restarted.
- No code after the ExecuteGame() call in the script will be run.
- In Sphere v0.97 and earlier, the behaviour is different. In these versions of the game engine, when the second game ends, Sphere carries on in the first game where it left off. This means code after the ExecuteGame() call will still run. It is not recommended that you rely on this logic.
[edit]
See also
- OpenFile()

