set: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "[[Category:Scripting Commands ArmA|" to "[[Category:Scripting Commands Armed Assault|")
m (Replaced <code> with <sqf>)
(48 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| ofpr |Game name=
|game1= ofp
|version1= 1.75


|1.75|Game version=
|game2= ofpe
____________________________________________________________________________________________
|version2= 1.00


| Changes the element at the given (zero-based) index of the [[Array|array]].
|game3= arma1
<br>If the element does not exist, [[resize]] index+1 is called to create it. |DESCRIPTION=
|version3= 1.00
____________________________________________________________________________________________


| array '''set''' [index, value] |SYNTAX=
|game4= arma2
|version4= 1.00


|p1= array: [[Array]] |PARAMETER1=
|game5= arma2oa
|p2= [index, value]: [[Array]] |PARAMETER2=
|version5= 1.50
|p3= index: [[Number]] |PARAMETER3=
|p4= value: [[Anything]] |PARAMETER4=


| [[Nothing]] |RETURNVALUE=
|game6= tkoh
____________________________________________________________________________________________
|version6= 1.00
 
|x1= <code>_arrayOne [[set]] [0, "Hello"];</code> |EXAMPLE1=


|x2= <code>_arrayTwo [[set]] [<nowiki/>[[count]] _arrayTwo, "Bye"];</code>
|game7= arma3
appends "Bye" as last element to <tt>_arrayTwo</tt> |EXAMPLE2=
|version7= 0.50


|gr1= Arrays


|x3= <code>_arrayThree [[set]] [<nowiki/>([[count]] _arrayThree) - 1, 23];</code>
|gr2= HashMap
replaces the last element of <tt>_arrayTwo</tt> with 23 |EXAMPLE3=
____________________________________________________________________________________________


| [[Array]], [[plus a]], [[valuea plus valueb]], [[a - b]], [[resize]], [[reverse]], [[select]], [[in]], [[find]], [[findIf]], [[toArray]], [[toString]], [[forEach]], [[count]], [[pushBack]], [[pushBackUnique]], [[apply]], [[deleteAt]], [[deleteRange]], [[append]], [[sort]], [[param]], [[params]], [[arrayIntersect]], [[splitString]], [[joinString]]|SEEALSO=
|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 {{HashLink|#Example 4}}).


}}
|s1= array [[set]] [index, value]
 
|p1= array: [[Array]]
 
|p2= index: [[Number]]
 
|p3= value: [[Anything]]
 
|r1= [[Nothing]]
 
|s2= hashMap [[set]] [key, value, insertOnly]
 
|s2since= arma3 2.02
 
|p21= hashMap: [[HashMap]]
 
|p22= key: [[HashMapKey]]
 
|p23= value: [[Anything]]
 
|p24= insertOnly: [[Boolean]] - (Optional, default [[false]]) if set to [[true]], set the value only if the key does not exist already
|p24since= arma3 2.08
 
|r2= [[Boolean]] - [[false|False]] if the key is new to the hashmap, [[true]] if a value got overwritten
 
|x1= <sqf>_arrayOne set [0, "Hello"];</sqf>
 
|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:
<sqf>_arrayThree set [(count _arrayThree) - 1, 23];</sqf>


<h3 style="display:none">Notes</h3>
|x4= Using [[set]] with an index that is out of bounds:
<dl class="command_description">
<sqf>private _array = ["A"];
<!-- Note Section BEGIN -->
_array set [2, "C"]; // _array is now ["A", nil, "C"]
_array set [1, "B"]; // _array is now ["A", "B", "C"]</sqf>


<!-- Note Section END -->
|x5= <sqf>private _myHashMap = createHashMap;
</dl>
_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>


<h3 style="display:none">Bottom Section</h3>
|seealso= [[resize]] [[reverse]] [[select]] [[deleteAt]] [[deleteRange]]  
[[Category:Scripting Commands|SET]]
}}
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.96|SET]]
[[Category:Scripting Commands Armed Assault|SET]]
[[Category:Scripting Commands Arma 2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Take On Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]

Revision as of 16:43, 14 May 2022

Hover & click on the images for description

Description

Description:
Changes the element at the given zero-based index of the 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 Example 4).
Groups:
ArraysHashMap

Syntax

Syntax:
array set [index, value]
Parameters:
array: Array
index: Number
value: Anything
Return Value:
Nothing

Alternative Syntax

Syntax:
hashMap set [key, value, insertOnly]
Parameters:
hashMap: HashMap
key: HashMapKey
value: Anything
since Arma 3 logo black.png2.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:
_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

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