setVariable
Jump to navigation
Jump to search
Description
- Description:
- Set variable to given value in the variable space of given element.
To remove a variable, set it to nil (e.g.player setVariable ["varname", nil];
).
When variable is set on Task, it is not actually set on task itself, but on FSM attached to the task. So if there is no FSM setVariable will not work.
All available data type combinations: - Multiplayer:
- The variable space of the object is local to each client and by default changes are not broadcast.
Since Arma 2: If the public parameter for supported types is true, the value will be synchronized also for a JIP player. - Groups:
- Uncategorised
Syntax
- Syntax:
- objectName setVariable [name, value, public]
- Parameters:
- objectName: Object or Location - Arma 2 also supports: Namespace, Group, Control, Task
- [name, value]: Array
- name: String
- value: Anything - (if public is true, check publicVariable for what types are supported for broadcast)
- public (Optional): Boolean - Only available for Object types and (since Arma 1.48) for missionNamespace. If public is true then the value is broadcast to all computers. Template:EffArg
- Return Value:
- Nothing
Examples
- Example 1:
_myTruck setVariable ["myPublicVariable", 123, true];
- Example 2:
_myTruck setVariable ["myLocalVariable", ["321", _var], false];
- Example 3:
missionNamespace setVariable ["myName", "KK"]; hint myName; //KK
- Example 4:
- Get current value of a variable and if it is undefined, define it and get the defined value:
private _var = missionNamespace getVariable "varName"; if (isNil "_var") then { missionNamespace setVariable ["varName", 123]; _var = 123; }; // _var here will contain current value of the variable varName
Additional Information
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Notes
- Posted on 18 August, 2007 - 09:51
- 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." Reference: Make setVariable work on other things than just vehicles
- Posted on 3 November, 2009 - 19:40 (CEST)
- .kju
- Public variable parameter works also for groups in ArmA II. Ref: A2 CIT.
- Posted on January 18, 2010 - 17:27 (CEST)
- Lou Montana
- this command doesn't work with tasks in Arma 2 1.05
- Posted on February 8, 2010 - 18:42 (CEST)
- LaKing
- In Arma 2 1.05 the missionNamespace object allows only the two main Arguments by syntax. Publishing the Variable afterwards works fine.
- Posted on January 25, 2011 - 02:48 (CEST)
- Lou Montana
- this command does work with tasks in Arma 2 OA 1.57
- Posted on 19 July, 2011
- kju
- My finds with 1.59 are:
- Posted on 8 May, 2012
- Krause
- IMPORTANT: This will not work on groups if you do it from the init line (you'll experience locality issues). Do something like this instead:
Put this on init line:
b_GroupSetup = [ group this, "3/B", "Tank", "Platoon"] execVM "grouptest.sqf";
grouptest.sqf:if (isServer) then { private ["_GroupSelect", "_GroupDesig", "_GroupType", "_GroupSize"]; _GroupSelect = _this select 0; _GroupDesig = _this select 1; _GroupType = _this select 2; _GroupSize = _this select 3; _GroupSelect setVariable ["groupDetails", [_GroupDesig, _GroupType, _GroupSize, 0, [], ""], true ]; };
Bottom Section
- Posted on June 13, 2014 - 19:19 (UTC)
- Astus Darkblossom
- (A3) Disable randomization and set a color to randomized vehicles by using ‘this setVariable ["color",X]’ in the init of the vehicle where X is a number ranging from 0 to the number of skins (minus 1). If the number is out of range, the skin is still randomized.
- Posted on December 9, 2015 - 20:18 (UTC)
- Commy2
- This command does not work with CfgAmmo or CfgNonAIVehicles objects, like bullets, mines or butterflies.
Categories:
- Scripting Commands
- Introduced with Arma version 1.00
- Arma: New Scripting Commands
- Arma: Scripting Commands
- Command Group: Uncategorised
- Scripting Commands: Local Effect
- Scripting Commands OFP Elite
- Scripting Commands ArmA
- Command Group: Locations
- Command Group: Object Information
- Command Group: Variables
- Scripting Commands ArmA2
- Scripting Commands Arma 3
- Scripting Commands Take On Helicopters