getOrDefaultCall: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Created page with "{{RV|type=command |game1= arma3 |version1= 2.12 |branch=dev |gr1= HashMap |descr= Retrieves a value from the HashMap for the given 'key', executes given 'code' if key w...")
 
m (fixed typo in example)
Line 21: Line 21:
|r1= [[Anything]]
|r1= [[Anything]]


|x1= <sqf>_hashmap getOrDefaultCall [123, { systemChat "The key 123 does not exist and will be created and assigned 345", 345 }, true]</sqf>
|x1= <sqf>_hashmap getOrDefaultCall [123, { systemChat "The key 123 does not exist and will be created and assigned 345"; 345 }, true]</sqf>


|seealso= [[getOrDefault]] [[HashMap]] [[get]]
|seealso= [[getOrDefault]] [[HashMap]] [[get]]
}}
}}

Revision as of 17:31, 8 September 2022

Hover & click on the images for description
Only available in Development branch(es) until its release with Arma 3 patch v2.12.

Description

Description:
Retrieves a value from the HashMap for the given 'key', executes given 'code' if key was not found and returns result. Additionally sets key to the code result value if 'set' is true.
Groups:
HashMap

Syntax

Syntax:
hashMap getOrDefaultCall [key, code, set]
Parameters:
hashMap: HashMap
key: HashMapKey - Case sensitive key
code: Code - (Optional, default nil) - Code to execute if the key does not exist
set: Boolean - (Optional, default false) if true and value does not exist in provided hash map, the result of the 'code' execution will be added to the hash map
Return Value:
Anything

Examples

Example 1:
_hashmap getOrDefaultCall [123, { systemChat "The key 123 does not exist and will be created and assigned 345"; 345 }, true]

Additional Information

See also:
getOrDefault HashMap get

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