set: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - "\|x([0-9])= *<code>([^<]*)<\/code>" to "|x$1= <sqf>$2</sqf>") |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 26: | Line 26: | ||
|gr2= HashMap | |gr2= HashMap | ||
|descr= Changes the element at the given zero-based index of the [[Array|array]]. 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 {{ | |descr= Changes the element at the given zero-based index of the [[Array|array]]. | ||
{{Feature|informative|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 {{Link|#Example 4}}). }} | |||
|s1= array [[set]] [index, value] | |s1= array [[set]] [index, value] | ||
Line 32: | Line 34: | ||
|p1= array: [[Array]] | |p1= array: [[Array]] | ||
|p2= index: [[Number]] | |p2= index: [[Number]] - 0-based array index. {{GVI|arma3|2.12|size= 0.75}} negative index can be used to select from the end of the array, i.e. -1 means last array element. | ||
|p3= value: [[Anything]] | |p3= value: [[Anything]] | ||
Line 51: | Line 53: | ||
|p24since= arma3 2.08 | |p24since= arma3 2.08 | ||
|r2= [[Boolean]] - [[false | |r2= [[Boolean]] - [[false]] if the key is new to the hashmap, [[true]] if a value got overwritten | ||
|x1= <sqf>_arrayOne set [0, "Hello"];</sqf> | |x1= <sqf>_arrayOne set [0, "Hello"];</sqf> | ||
|x2= Append "Bye" as last element to {{hl|_arrayTwo}}: | |x2= Append "Bye" as last element to {{hl|_arrayTwo}}: | ||
< | <sqf>_arrayTwo set [count _arrayTwo, "Bye"];</sqf> | ||
|x3= Replace the last element of {{hl|_arrayThree}} with 23: | |x3= Replace the last element of {{hl|_arrayThree}} with 23: | ||
< | <sqf>_arrayThree set [(count _arrayThree) - 1, 23];</sqf> | ||
|x4= Using [[set]] with an index that is out of bounds: | |x4= Using [[set]] with an index that is out of bounds: | ||
< | <sqf> | ||
private _array = ["A"]; | |||
_array set [2, "C"]; // _array is now ["A", nil, "C"] | _array set [2, "C"]; // _array is now ["A", nil, "C"] | ||
_array set [1, "B"]; // _array is now ["A", "B", "C"]</ | _array set [1, "B"]; // _array is now ["A", "B", "C"] | ||
</sqf> | |||
|x5= <sqf>private _myHashMap = createHashMap; | |x5= <sqf> | ||
private _myHashMap = createHashMap; | |||
_myHashMap set ["key", "value1", true]; // "key" value is set to "value1" | _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</sqf> | _myHashMap set ["key", "value2", true]; // "key" value is still "value1" as "key" already exists in the hashmap | ||
</sqf> | |||
|seealso= [[resize]] [[reverse]] [[select]] [[deleteAt]] [[deleteRange]] | |seealso= [[resize]] [[reverse]] [[select]] [[deleteAt]] [[deleteRange]] | ||
}} | }} |
Latest revision as of 20:21, 29 April 2023
Description
Syntax
- Syntax:
- array set [index, value]
- Parameters:
- array: Array
- index: Number - 0-based array index. 2.12 negative index can be used to select from the end of the array, i.e. -1 means last array element.
- value: Anything
- Return Value:
- Nothing
Alternative Syntax
- Syntax:
- hashMap set [key, value, insertOnly]
- Parameters:
- hashMap: HashMap
- key: HashMapKey
- value: Anything
- since 2.08
- insertOnly: Boolean - (Optional, default false) if set to true, set the value only if the key does not exist already
- Return Value:
- 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:
- Example 3:
- Replace the last element of _arrayThree with 23:
- Example 4:
- Using set with an index that is out of bounds:
- 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
Additional Information
- See also:
- resize reverse select deleteAt deleteRange
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
Categories:
- Scripting Commands
- Introduced with Operation Flashpoint version 1.75
- Operation Flashpoint: New Scripting Commands
- Operation Flashpoint: Scripting Commands
- Operation Flashpoint: Elite: Scripting Commands
- ArmA: Armed Assault: Scripting Commands
- Arma 2: Scripting Commands
- Arma 2: Operation Arrowhead: Scripting Commands
- Take On Helicopters: Scripting Commands
- Arma 3: Scripting Commands
- Command Group: Arrays
- Command Group: HashMap