BIS fnc addToPairs: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - " (\|[pr][0-9]+ *= *[^-]+) *- *A([a-z])" to " $1 - a$2") |
Lou Montana (talk | contribs) m (Text replacement - "{{Feature|Informative|" to "{{Feature|informative|") |
||
(2 intermediate revisions by the same user not shown) | |||
Line 13: | Line 13: | ||
c) anything else: an array is created and both values are stored there<br><br> | c) anything else: an array is created and both values are stored there<br><br> | ||
{{Feature| | {{Feature|informative|Function by default modifies the input array. This can be overrriden by setting '_copyArray' param to true.}} | ||
|s1= [array, key, value, copyArray] call [[BIS_fnc_addToPairs]] | |s1= [array, key, value, copyArray] call [[BIS_fnc_addToPairs]] | ||
Line 19: | Line 19: | ||
|p1= array: [[Array]] - array to search through | |p1= array: [[Array]] - array to search through | ||
|p2= key: [[String]] - | |p2= key: [[String]] - key to search for | ||
|p3= value: [[Number]] - (Optional, default [[nil]]) default return value if no match was found | |p3= value: [[Number]] - (Optional, default [[nil]]) default return value if no match was found | ||
Line 25: | Line 25: | ||
|p4= copyArray: [[Boolean]] - (Optional, default [[false]]) [[true]] to copy the array and return it, [[false]] to modify the original array | |p4= copyArray: [[Boolean]] - (Optional, default [[false]]) [[true]] to copy the array and return it, [[false]] to modify the original array | ||
|r1= [[Array]] - | |r1= [[Array]] - resulting modified array or a copy | ||
|x1= <sqf>[[["apple",3],["pear",2]],"pear",10] call BIS_fnc_addToPairs; // Returns [["apple",3],["pear",12]]</sqf> | |x1= <sqf>[[["apple",3],["pear",2]],"pear",10] call BIS_fnc_addToPairs; // Returns [["apple",3],["pear",12]]</sqf> |
Latest revision as of 00:24, 2 February 2024
Description
- Description:
- Adds given value to pair array, stored under unique key.
If value is found:
a) both values are scalars: values are added and stored as a single scalar
b) one or both values are array: values are added and stored as a single array
c) anything else: an array is created and both values are stored there
- Execution:
- call
- Groups:
- Arrays
Syntax
- Syntax:
- [array, key, value, copyArray] call BIS_fnc_addToPairs
- Parameters:
- array: Array - array to search through
- key: String - key to search for
- value: Number - (Optional, default nil) default return value if no match was found
- copyArray: Boolean - (Optional, default false) true to copy the array and return it, false to modify the original array
- Return Value:
- Array - resulting modified array or a copy
Examples
- Example 1:
- Example 2:
- Example 3:
- [[["greetings","Hello!"],["rudewords",""]],"greetings","Hi!"] call BIS_fnc_addToPairs; // Returns [["greetings",["Hello!","Hi!"]],["rudewords",""]]
Additional Information
- See also:
- find findIf BIS_fnc_findInPairs BIS_fnc_getFromPairs BIS_fnc_removeFromPairs BIS_fnc_setToPairs
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