Category: Objects
/ Commands
Since engine version: 1.0 OC
AddCommand
Description
Adds a command to the top of the command stack of an object (also see AppendCommand). This command will be executed first, then the object will continue with the existing commands. If the command stack is empty, AddCommand does the same as SetCommand.
For the list of commands see SetCommand.
For the list of commands see SetCommand.
Syntax
bool AddCommand(string command, object target, int x, int y, object target2, int delay, any Data, int retries, int base_mode);
Parameters
- command:
- Command name (as string). See the table below.
- target:
- [opt] target object for the command
- x:
- [opt] X target coordinate
- y:
- [opt] Y target coordinate
- target2:
- [opt] secondary target object
- delay:
- [opt] Time (in ticks or frames) until the command is automatically aborted. Execution will continue with the next command in the stack.
- Data:
- [opt] additional data for the command
- retries:
- [opt] Number of retries if the command fails, until the command fails completely.
- base_mode:
- [opt] Determines the behaviour if the command fails.
base_mode Name Description Failure messages and CallFailed calls Next command 0 C4CMD_SilentSub Silent command Only if this is the last command Fails 3 C4CMD_Sub Command If the next command has no retries left or this is the last command. Fails 2 C4CMD_SilentBase Silent base command Never Does not fail 1 C4CMD_Base Base command Always Does not fail
Remark
Commands added using AddCommand are not passed to controlled vehicles (see VehicleControl).
Example
var obj = FindObject(Find_InRect(-20, -40, 40, 40), Find_OCF(OCF_CrewMember)); if(obj) if(obj->GetComDir() == COMD_Right) obj->AddCommand("Jump"); return;
If called from an object on the ground, this timer script makes any clonk passing the object from left to right jump. To do this, crew member objects are searched above the object. If one is found and he is moving from left to right (ComDir), he is given a 'Jump' command. Notice that this does not affect the previously set commands of the clonk - after completing the jump command, the clonk will continue with his previous commands. Using this script, you could e.g. ensure that clonks will always jump a given gap in the landscape.