Arma 3 Scripting

Command in Arrays, HashMap

set

Also available as Markdown and JSON, or read the original wiki page.

Description

Changes the element at the given zero-based index of the array.

Note

If the index is out of bounds, the array will resize to incorporate the index as its last value, padding with nil as necessary (see #Example 4).

Syntax

Syntax 1

array set [index, value]

Parameters:

Returns: Nothing

Syntax 2

since arma3 2.02

hashMap set [key, value, insertOnly]

Parameters:

Returns: Boolean - false if the key is new to the hashmap, true if a value got overwritten

Examples

Example 1

_arrayOne set [0, "Hello"];

Example 2

Append "Bye" as last element to _arrayTwo:

_arrayTwo set [count _arrayTwo, "Bye"];

Example 3

Replace the last element of _arrayThree with 23:

_arrayThree set [(count _arrayThree) - 1, 23];

Example 4

Using set with an index that is out of bounds:

private _array = ["A"];
_array set [2, "C"]; // _array is now ["A", nil, "C"]
_array set [1, "B"]; // _array is now ["A", "B", "C"]

Example 5

private _myHashMap = createHashMap;
_myHashMap set ["key", "value1", true]; // "key" value is set to "value1"
_myHashMap set ["key", "value2", true]; // "key" value is still "value1" as "key" already exists in the hashmap

See also

resize · reverse · select · deleteAt · deleteRange