Public Member Functions
|GSController (CompanyID company)|
|Initializer of the GSController. |
|This function is called to start your script. |
|Save the state of the script. |
|void||Load (int version, SquirrelTable data)|
|Load saved data just before calling Start. |
Static Public Member Functions
|static uint||GetTick ()|
|Find at which tick your script currently is. |
|static int||GetOpsTillSuspend ()|
|Get the number of operations the script may still execute this tick. |
|static int||GetSetting (const char *name)|
|Get the value of one of your settings you set via info.nut. |
|static uint||GetVersion ()|
|Get the OpenTTD version of this executable. |
|static void||SetCommandDelay (int ticks)|
|Change the minimum amount of time the script should be put in suspend mode when you execute a command. |
|static void||Sleep (int ticks)|
|Sleep for X ticks. |
|static void||Break (const char *message)|
|Break execution of the script when script developer tools are active. |
|static void||Print (bool error_msg, const char *message)|
|When Squirrel triggers a print, this function is called. |
|static HSQOBJECT||Import (const char *library, const char *class_name, int version)|
|Import a library. |
It creates the GS, makes sure the logic kicks in correctly, and that GetTick() has a valid value.
When starting a new game, or when loading a game, OpenTTD tries to match a script that matches to the specified version as close as possible. It tries (from first to last, stopping as soon as the attempt succeeds)
After determining the script to use, starting it is done as follows
See also http://wiki.openttd.org/AI:Save/Load for more details.
Initializer of the GSController.
|company||The company this GS is normally serving.|
This function is called to start your script.
Your script starts here. If you return from this function, your script dies, so make sure that doesn't happen.
Save the state of the script.
By implementing this function, you can store some data inside the savegame. The function should return a table with the information you want to store. You can only store:
In particular, instances of classes can't be saved including GSList. Such a list should be converted to an array or table on save and converted back on load.
The function is called as soon as the user saves the game, independently of other activities of the script. The script is not notified of the call. To avoid race-conditions between Save and the other script code, change variables directly after a Sleep, it is very unlikely, to get interrupted at that point in the execution. See also http://wiki.openttd.org/AI:Save/Load for more details.
|static uint GSController::GetTick||(||)||
Find at which tick your script currently is.
|static int GSController::GetOpsTillSuspend||(||)||
Get the number of operations the script may still execute this tick.
|static int GSController::GetSetting||(||const char *||name||)||
Get the value of one of your settings you set via info.nut.
|name||The name of the setting.|
|static uint GSController::GetVersion||(||)||
Get the OpenTTD version of this executable.
The version is formatted with the bits having the following meaning: 28-31 major version 24-27 minor version 20-23 build 19 1 if it is a release, 0 if it is not. 0-18 revision number; 0 when the revision is unknown.
|static void GSController::SetCommandDelay||(||int||ticks||)||
Change the minimum amount of time the script should be put in suspend mode when you execute a command.
Normally in SP this is 1, and in MP it is what ever delay the server has been programmed to delay commands (normally between 1 and 5). To give a more 'real' effect to your script, you can control that number here.
|ticks||The minimum amount of ticks to wait.|
|static void GSController::Sleep||(||int||ticks||)||
Sleep for X ticks.
The code continues after this line when the X script ticks are passed. Mind that an script tick is different from in-game ticks and differ per script speed.
|ticks||the ticks to wait|
|static void GSController::Break||(||const char *||message||)||
Break execution of the script when script developer tools are active.
For other users, nothing will happen when you call this function. To resume the script, you have to click on the continue button in the AI debug window. It is not recommended to leave calls to this function in scripts that you publish or upload to bananas.
|message||to print in the AI debug window when the break occurs.|
|static void GSController::Print||(||bool||error_msg,|
|const char *||message|
When Squirrel triggers a print, this function is called.
Squirrel calls this when 'print' is used, or when the script made an error.
|error_msg||If true, it is a Squirrel error message.|
|message||The message Squirrel logged.|
|static HSQOBJECT GSController::Import||(||const char *||library,|
|const char *||class_name,|
Import a library.
|library||The name of the library to import. The name should be composed as GSInfo::GetCategory() + "." + GSInfo::CreateInstance().|
|class_name||Under which name you want it to be available (or "" if you just want the returning object).|
|version||Which version you want specifically.|