Page tree
Skip to end of metadata
Go to start of metadata


Introduced in

Version:1.19

Description

Description:

Sets the variable to the given value in the variable space of the given element.

To remove a variable, set it to nil (for example, player setVariable ["varname",nil]).

Variables can only be set for existing entities. Once an entity is removed, all associated variables are removed as well. Variables can be assigned to the following entities:

Note: Only Object is possible, if recordForAAR option is set to true (see Syntax).

Syntax

Syntax:element setVariable [name, value, public, resetOnRespawn, recordForAAR]
Parameters:
  • element: Anything - Entity to assign a variable to (see description for compatible types).
  • name: String - Name of variable (case-sensitive).
  • value: Anything - Value to assign to variable (see Notes under recordForAAR for limitations).
  • public: Boolean - If true, then the value is broadcast to all computers (works with Object, Groupand Waypoint). Generates a syntax error, if used with Namespace (optional, default: false).
  • resetOnRespawn: Boolean - Clear variable on respawn (optional, default: false) (V2.03+).
  • recordForAAR: Boolean - Whether the variable should be available in AAR. If true, then element can only be an Object, and value can only contain String, Number, Array, or a combination of these (optional, default: false) (V3.4+).
Return Value:Nothing

Alternative Syntax

Syntax:map setVariable [name, value, clear] (V2.0+)
Parameters:
  • map: Control - Editor map (only applicable to the Editor Map Control).
  • name: String - Name of variable (case-sensitive)
  • value: Anything - Value to assign to the variable.
  • clear: Boolean - If true, then the variable is reset during the mission: "Clear", "Load" or "Save". If false, then the values are retained (optional, default: true).
Return Value:Nothing

Examples

Examples:
car1 setVariable ["owner",player,true];

Additional Information

See also: getVariable, VBS Object Variables
Multiplayer:
Problems:

Notes







Posted on Feb 13, 2012
Kronzky
If the value stored via setVariable is an array, then its value can be changed by reference:


player setVariable ["myArray", [1,2,3]];
_ptr = player getVariable "myArray";   // _ptr is pointer to [1,2,3], so is "myArray" on player
_ptr set [1,4]; // modiying the pointer will modify the value stored in "myArray"
player sidechat str(_ptr); // now returns [1,4,3]
player sidechat str(player getVariable "myArray"); // returns [1,4,3] as well

// If the variable name is re-assigned, it will become "disconnect" from the original pointer
player setVariable ["myArray", [1,2,3]];
player sidechat str(_ptr); // still returns [1,4,3] (from the original array reference)
player sidechat str(player getVariable "myArray"); // returns [1,2,3] (the newly assigned array values)