Executes the code on all computers, where
Note: If a command is a "relative" action (for example, incrementally increasing damage, or moving something in steps), executing it on more than one machine has a cumulative effect, since it is executed several times. For example, if 10 machines are on the network, and the following command is executed, then the tank gets fully destroyed after
|Syntax:||publicExec [condition, code, object, executeOnThisClient]|
|See also:||local (Command), executeWhereLocal|
- Posted on Apr 30, 2014
- While you can pass just a single object to the publicExec command. It's better to pass that object as an array instead, for example:
publicExec ["local (_this select 0)","(_this select 0) setFuel 0",[tank1]]
The reason being, if for some reason the object is no longer valid, the publicExec command will convert that null object to an empty array  and pass it the condition and execution code. This can often happen with clients disconnecting from a Multi Player session, resulting in the following error:
Type Array, expected Object; CurrentValue: 
If you pass your single object as an array instead, the null object will be converted as follows [objNull]. Which in the majority of cases, will be processed without generating any errors or any adverse impact.
- Posted on Nov 06, 2008
- General Barron
- Note that you can only pass an object or an array of objects in to the code's _this variable.
If you try to pass a null object, the object will NOT be passed. While this would be an odd thing to do, there could be a situation where a variable turns into a null object unexpectedly, and you then try to pass it into the code.
To pass other data types into the code, you need to use the format command to modify the code string. Example:
_num = random 1; publicExec ["true", format["setOvercast %1", _num]];