QueuePersonScript
From Spheriki
Adds some JavaScript code to a person's command queue.
Contents |
Usage
- person_name string. The name of the person to add the script to.
- script string. The JavaScript code to add to the person's queue.
- immediate boolean. If false the mapengine will stop executing the person's command queue after evaluating the script and won't resume its execution until the next mapengine update. If true the following queued scripts or commands are executed within the current update until one script or command has 'immediate' set to false.
Examples
To make "Bob" teleport after walking around a bit, do something like:
for (var i = 0; i < 16; ++i) QueuePersonCommand("Bob", COMMAND_MOVE_SOUTH, false); for (var i = 0; i < 16; ++i) QueuePersonCommand("Bob", COMMAND_MOVE_WEST, false); for (var i = 0; i < 16; ++i) QueuePersonCommand("Bob", COMMAND_MOVE_NORTH, false); for (var i = 0; i < 16; ++i) QueuePersonCommand("Bob", COMMAND_MOVE_EAST, false); QueuePersonScript("Bob", "SetPersonXYFloat('Bob', 32, 32);", false);
Now "Bob" will teleport to (32, 32) after he walks around in a square.
Notes
- Note that the script is a string, which is evaluated to JavaScript code at runtime. This means that errors that Sphere picks up in the rest of your scripts won't be found in these "script strings" until Sphere runs into them. Be careful when writing code for the script parameter.
- The command queue is automatically processed by the Sphere map engine. For each map engine update and person, it'll execute the next queued scripts or commands that have their 'immediate' flag set to true until one has the flag set to false. This last one will be executed too during the current update, while execution of the following queued scripts or commands will be continued during the next update.
- For more conventional use of the person command queue, see QueuePersonCommand().