set: Difference between revisions
Jump to navigation
Jump to search
m (Text replacement - "{{uc:{{PAGENAME}}}}" to "") |
(Changed description, reformatted examples, added example 4) |
||
Line 9: | Line 9: | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| Changes the element at the given (zero-based) index of the [[Array|array]]. | | Changes the element at the given (zero-based) index of the [[Array|array]].<br> | ||
<br>If the | If the index is out of bounds, the array will [[resize]] to incorporate the index as its last value, padding with [[nil]] as necessary. |DESCRIPTION= | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
Line 25: | Line 25: | ||
|x1= <code>_arrayOne [[set]] [0, "Hello"];</code> |EXAMPLE1= | |x1= <code>_arrayOne [[set]] [0, "Hello"];</code> |EXAMPLE1= | ||
|x2= <code>_arrayTwo [[set]] [<nowiki/>[[count]] _arrayTwo, "Bye"];</code | |x2= Append "Bye" as last element to <tt>_arrayTwo</tt>:<br> | ||
<code>_arrayTwo [[set]] [<nowiki/>[[count]] _arrayTwo, "Bye"];</code> |EXAMPLE2= | |||
|x3= Replace the last element of <tt>_arrayThree</tt> with 23:<br> | |||
<code>_arrayThree [[set]] [<nowiki/>([[count]] _arrayThree) - 1, 23];</code> |EXAMPLE3= | |||
| | |x4 = Using [[set]] with an index that is out of bounds:<br> | ||
<code>_array = ["A"]; | |||
_array [[set]] [2, "C"]; {{cc|_array is now ["A", [[nil]], "C"]}} | |||
_array [[set]] [1, "B"]; {{cc|_array is now ["A", "B", "C"]}} | |||
</code> |EXAMPLE4= | |||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
Revision as of 16:26, 3 December 2020
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. - Groups:
- Arrays
Syntax
- Syntax:
- array set [index, value]
- Parameters:
- array: Array
- [index, value]: Array
- index: Number
- value: Anything
- Return Value:
- Nothing
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
Notes
Bottom Section
Categories:
- Scripting Commands
- Introduced with Operation Flashpoint: Resistance version 1.75
- Operation Flashpoint: Resistance: New Scripting Commands
- Operation Flashpoint: Resistance: Scripting Commands
- Command Group: Arrays
- Scripting Commands OFP 1.99
- Scripting Commands OFP 1.96
- Scripting Commands Armed Assault
- Scripting Commands Arma 2
- Scripting Commands Arma 3
- Scripting Commands Take On Helicopters