Arma 3 Scripting

setVariable

  • Global argument
  • Local effect
  • Arma 3 v0.50
  • First in Armed Assault v1.00

Command · also in Namespaces, Multiplayer · Markdown · JSON · original wiki page

Description

Set variable to given value in the variable space of given element. Can be used to broadcast variables over the network.

To remove a variable, set it to nil (see #Example 5) - note that this does not work on Object and scripted Location namespaces (the variable will be set to nil but will remain listed by allVariables).

Warning

missionNamespace, uiNamespace, parsingNamespace and profileNamespace variables cannot be named as commands - e.g missionNamespace setVariable ["west", 123]; conflicts with the west command and will result in a Reserved variable in expression error, west being a scripting command (other namespaces do not have such limitation). See also all available script commands.

Syntax

varspace setVariable [name, value, public]

Parameters:

Returns: Nothing

Examples

Example 1

_myTruck setVariable ["TAG_myPublicVariable", 123, true];

Example 2

_myTruck setVariable ["TAG_myLocalVariable", ["321", _var], owner driver _myTruck];

Example 3

missionNamespace setVariable ["TAG_myName", "Brian"];
hint TAG_myName; // hints "Brian"

Example 4

Get the current value of a variable or, if it is undefined, define it and then get the value:

private _var = missionNamespace getVariable "VarName";
if (isNil "_var") then
{
    _var = 123;
    missionNamespace setVariable ["VarName", _var];
};
// _var now contains the current value of the missionNamespace's variable varName

Example 5

Remove TAG_myPublicVariable from missionNamespace (globally):

missionNamespace setVariable ["TAG_myPublicVariable", nil, true];

See also

getVariable · allVariables · setFSMVariable

Community notes

Killswitch

According to Suma, beginning with ArmA version 1.08:

setVariable now should work on any entity which can be targeted by AI, including soldier and game logic units. This includes most buildings, but not other static objects. Using it with buildings one should be aware the building may be discarded because of streaming. In such case the variable space is lost. When used for buildings, the storage should therefore be considered non-reliable.

Commy2

This command does not work with CfgAmmo or CfgNonAIVehicles objects, like bullets, mines or butterflies.

Leopard20

Since Arma 3 v2.10 setVariable works on CfgAmmo objects (such as bullets, missiles, grenades, mines, etc) as well.