getOrDefaultCall: Difference between revisions
m (fixed typo in example) |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 3: | Line 3: | ||
|game1= arma3 | |game1= arma3 | ||
|version1= 2.12 | |version1= 2.12 | ||
|gr1= HashMap | |gr1= HashMap | ||
|descr= 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. | |descr= 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. | |||
|s1= hashMap [[getOrDefaultCall]] [key, code, set] | |s1= hashMap [[getOrDefaultCall]] [key, code, set] | ||
| Line 13: | Line 13: | ||
|p1= hashMap: [[HashMap]] | |p1= hashMap: [[HashMap]] | ||
|p2= key: [[HashMapKey]] - | |p2= key: [[HashMapKey]] - case-sensitive key | ||
|p3= code: [[Code]] - (Optional, default [[nil]]) | |p3= code: [[Code]] - (Optional, default [[nil]]) code to execute if the key does not exist | ||
|p4= set: [[Boolean]] - (Optional, default [[false]]) if [[true]] and value does not exist in provided hash map, the result of the 'code' execution | |p4= set: [[Boolean]] - (Optional, default [[false]]) if [[true]] and value does not exist in the provided hash map, the result of the ''code'' execution is added to the hash map | ||
|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]] | ||
}} | }} | ||
Latest revision as of 02:21, 26 March 2026
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 the provided hash map, the result of the code execution is 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.
Only post proven facts here! Add Note