Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


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:

Syntax

Syntax:element setVariable [name, value, public, resetOnRespawn, recordForAAR]
Parameters:
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)