BIS fnc addToPairs: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - " {{Function|Comments=" to "{{Function|Comments=")
m (page filled)
Line 1: Line 1:
{{Function|Comments=
{{Function
____________________________________________________________________________________________


| arma3 |Game name=
|game1= arma3


|0.76|Game version=
|version1= 0.76
____________________________________________________________________________________________


| <pre>/*
<!--|serverExec= server-->


Description:
<!--|arg= local-->
Adds given value to pair array, stored under unique key.


If value is found:
<!--|eff= local-->
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


Remarks:
|descr= Adds given value to pair array, stored under unique key.<br><br>
Function by default modifies the input array. This can be overrriden by setting '_copyArray' param to true.


Syntax:
If value is found:<br>
_pairs:array = [_pairs:array,_key:string,_value:number,_copyArray:bool] call BIS_fnc_addToPairs;
a) both values are scalars: values are added and stored as a single scalar<br>
b) one or both values are array: values are added and stored as a single array<br>
c) anything else: an array is created and both values are stored there<br><br>


Example:
{{Informative|Function by default modifies the input array. This can be overrriden by setting '_copyArray' param to true.}}
[["apple",3],["pear",12]] = [[["apple",3],["pear",2]],"pear",10] call BIS_fnc_addToPairs;
[["apple",1],["pear",2]] = [[["apple",3],["pear",2]],"apple",-2] call BIS_fnc_addToPairs;
[["greetings",["Hello!","Hi!"]],["rudewords",""]] = [[["greetings","Hello!"],["rudewords",""]],"greetings","Hi!"] call BIS_fnc_addToPairs;
*/


#define SCALAR (typeName 123)
|s1= [array, key, value, copyArray] call [[BIS_fnc_addToPairs]]
#define ARRAY (typeName [])


</pre><small>''(Placeholder description extracted from the function header by [[BIS_fnc_exportFunctionsToWiki]])''</small> |DESCRIPTION=
|p1= array: [[Array]] - Array to search through
____________________________________________________________________________________________


| <!-- [] call [[BIS_fnc_addToPairs]]; --> |SYNTAX=
|p2= key: [[String]] - Key to search for


|p1= |PARAMETER1=
|p3= value: [[Number]] - (Optional, default [[nil]]) Default return value if no match was found


| |RETURNVALUE=
|p4= copyArray: [[Boolean]] - (Optional, default [[false]]) [[True]] to copy the array and return it, [[false]] to modify the original array
____________________________________________________________________________________________


|x1= <code></code> |EXAMPLE1=
|r1= [[Number]] - Value associated with the key.
____________________________________________________________________________________________


| [[BIS_fnc_findInPairs]], [[BIS_fnc_setToPairs]] |SEEALSO=
|x1= <code>[[["apple",3],["pear",2]],"pear",10] [[call]] [[BIS_fnc_addToPairs]]; {{cc|Returns [["apple",3],["pear",12]]}}</code>


}}
|x2= <code>[[["apple",3],["pear",2]],"apple",-2] [[call]] [[BIS_fnc_addToPairs]]; {{cc|Returns [["apple",1],["pear",2]]}}</code>
 
|x3= <code>[[["greetings","Hello!"],["rudewords",""]],"greetings","Hi!"] [[call]] [[BIS_fnc_addToPairs]]; {{cc|Returns [["greetings",["Hello!","Hi!"]],["rudewords",""]]}}</code>


<h3 style="display:none">Notes</h3>
|exec= call
<dl class="command_description">
<!-- Note Section BEGIN -->


<!-- Note Section END -->
|seealso= [[find]] [[findIf]] [[BIS_fnc_findInPairs]] [[BIS_fnc_getFromPairs]]
</dl>


<h3 style="display:none">Bottom Section</h3>
}}
[[Category:Function Group: Arrays|{{uc:addToPairs}}]]
[[Category:Function Group: Arrays|{{uc:addToPairs}}]]
[[Category:Functions|{{uc:addToPairs}}]]
[[Category:Functions|{{uc:addToPairs}}]]
[[Category:{{Name|arma3}}: Functions|{{uc:addToPairs}}]]
[[Category:{{Name|arma3}}: Functions|{{uc:addToPairs}}]]

Revision as of 10:46, 15 September 2020

Hover & click on the images for description

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

Function by default modifies the input array. This can be overrriden by setting '_copyArray' param to true.
Execution:
call
Groups:
Uncategorised

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:
Number - Value associated with the key.

Examples

Example 1:
[[["apple",3],["pear",2]],"pear",10] call BIS_fnc_addToPairs; // Returns [["apple",3],["pear",12]]
Example 2:
[[["apple",3],["pear",2]],"apple",-2] call BIS_fnc_addToPairs; // Returns [["apple",1],["pear",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

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