Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
Invoke a function at some point in the future... |
Syntax
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
// syntax #1: optional game object as third parameter (WZ 3.1 b1+) queue(functionName, delay[, gameObject]); // syntax #2: optional string as third parameter (WZ 3.2+) queue(functionName, delay[, str]); |
Parameters
Syntax | Parameter | Type | Mandatory | Description | Game Version |
---|---|---|---|---|---|
All | functionName | String | A string containing the name of a global function to invoke. | 3.1 Beta 1 | |
All | delay | Number | You can optionally set a minimum amount of time (in milliseconds) before your function gets called. Delays should ideally be 500 or more, and never less than 100. If you don't specify this parameter, or specify 0 (zero), Warzone will choose a delay for you, usually the next a value lower than 1 game tick (100ms)100 milliseconds) the default value will be used. Default: 100 milliseconds | 3.1 Beta 1 | |
#1 | gameObject | Game object | An optional game object that will be passed in to your function when it gets called. The object will automatically be refreshed with the latest game data. If the object gets destroyed, the associated queued call will be cancelled automatically. | 3.1 Beta 1 | |
#2 | str | String | An optional string that will be passed in to your function when it gets called. | 3.2 |
Return value
Value | Type | Description | Game version |
---|---|---|---|
undefined | Undefined | The function was successfully queued. | 3.1 Beta 1 |
<error> | Error | Did you forget to specify functionName as a string? | 3.1 Beta 1 |
Notes
Unlike setTimer(), queue() does not repeat. It will make a single call to the named function at a later frame in the game.
You can cancel a queued call by calling removeTimer() (will also remove any timers associated with the function).
The function, when called, will be run in the context of the global scope ("this" will be the global scope).
Queued function calls persist the save/load cycle. You can therefore look at Saved game files to see what queued functions were defined at the time the game was saved.
When using syntax #1, if the game object is destroyed any queued function calls associated with it will be cancelled.
Example
Examples
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
function foo(gameObj) { // gameObj == someGameObject } // this syntax works on all versions WZ 3.1 and above queue("foo", 0, someGameObject); // global function foo will be called next game tick (100ms) // if someGameObject gets destroyed, the queued call will be cancelled |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
function bar(str) { // str = "hello" } // note: this syntax isrequires only available on Warzone WZ 3.2 andor above above queue("bar", 1000, "hello"); // global function bar will be called after 1 second |
Div | ||||||
---|---|---|---|---|---|---|
| ||||||
Availability
Requires:
|
Div | ||||
---|---|---|---|---|
| ||||
ContentsJump to:
|
Div | ||
---|---|---|
| ||
See alsoRelated functions:
|