set: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<h3 style="display:none">Bottom Section</h3> " to "")
m (Text replacement - " *\| *([Cc]omments|COMMENTS|Game|[Gg]ame [Nn]ame( +[0-9])?|Game [Vv]ersion( +[0-9])?|Game Version \(number surrounded by NO SPACES\)|Arguments in MP|MP[Aa]rg|Multiplayer Arguments( \("local" or "global"\))?|Effects|Execution|Effects...)
Line 1: Line 1:
{{Command|Comments=
{{Command


| ofpr |Game name=
| ofpr


|1.75|Game version=
|1.75


|gr1= Arrays |GROUP1=
|gr1= Arrays


| Changes the element at the given (zero-based) index of the [[Array|array]].<br>
| Changes the element at the given (zero-based) index of the [[Array|array]].<br>
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 [[set#Examples| Example 4]]. |DESCRIPTION=
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 [[set#Examples| Example 4]].


| array '''set''' [index, value] |SYNTAX=
| array '''set''' [index, value]


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


| [[Nothing]] |RETURNVALUE=
| [[Nothing]]




| s2= hashMap '''set''' [key, value] |SYNTAX2=
| s2= hashMap '''set''' [key, value]


|p21= hashMap : [[HashMap]] |PARAMETER21=
|p21= hashMap : [[HashMap]] |PARAMETER21=
Line 26: Line 26:
|p23= value: [[Anything]] |PARAMETER24=
|p23= value: [[Anything]] |PARAMETER24=


|r2= [[Boolean]] - [[false]] if the key is new to the hashmap, [[true]] if a value got overwritten |RETURNVALUE2=
|r2= [[Boolean]] - [[false]] if the key is new to the hashmap, [[true]] if a value got overwritten
   
   
|x1= <code>_arrayOne [[set]] [0, "Hello"];</code> |EXAMPLE1=
|x1= <code>_arrayOne [[set]] [0, "Hello"];</code>


|x2= Append "Bye" as last element to <tt>_arrayTwo</tt>:<br>
|x2= Append "Bye" as last element to <tt>_arrayTwo</tt>:<br>
<code>_arrayTwo [[set]] [<nowiki/>[[count]] _arrayTwo, "Bye"];</code> |EXAMPLE2=
<code>_arrayTwo [[set]] [<nowiki/>[[count]] _arrayTwo, "Bye"];</code>


|x3= Replace the last element of <tt>_arrayThree</tt> with 23:<br>
|x3= Replace the last element of <tt>_arrayThree</tt> with 23:<br>
<code>_arrayThree [[set]] [<nowiki/>([[count]] _arrayThree) - 1, 23];</code> |EXAMPLE3=
<code>_arrayThree [[set]] [<nowiki/>([[count]] _arrayThree) - 1, 23];</code>


|x4 = Using [[set]] with an index that is out of bounds:<br>
|x4 = Using [[set]] with an index that is out of bounds:<br>
Line 40: Line 40:
_array [[set]] [2, "C"]; {{cc|_array is now ["A", [[nil]], "C"]}}
_array [[set]] [2, "C"]; {{cc|_array is now ["A", [[nil]], "C"]}}
_array [[set]] [1, "B"]; {{cc|_array is now ["A", "B", "C"]}}
_array [[set]] [1, "B"]; {{cc|_array is now ["A", "B", "C"]}}
</code> |EXAMPLE4=
</code>


| [[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=
| [[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]]


}}
}}

Revision as of 11:03, 18 January 2021

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:
Arrays

Syntax

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

Alternative Syntax

Syntax:
hashMap set [key, value]
Parameters:
hashMap : HashMap
key: HashMapKey
value: Anything
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:
_array = ["A"]; _array set [2, "C"]; // _array is now ["A", nil, "C"] _array set [1, "B"]; // _array is now ["A", "B", "C"]

Additional Information

See also:
Arrayplus avaluea plus valueba - bresizereverseselectinfindfindIftoArraytoStringforEachcountpushBackpushBackUniqueapplydeleteAtdeleteRangeappendsortparamparamsarrayIntersectsplitStringjoinString

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