Arma 3 Scripting

Command in HashMap

getOrDefault

Also available as Markdown and JSON, or read the original wiki page.

Description

Retrieves a value out of a HashMap after looking it up by its key. When the HashMap doesn't contain the key, the default value is returned

Syntax

hashMap getOrDefault [key, defaultValue, setDefault]

Parameters:

Returns: Anything

Examples

Example 1

private _myValue = _myHashMap getOrDefault ["a", "Not Found!"];

Example 2

private _myValue = _hashMap getOrDefault ["a", "Not Found!", true]; // will add default value to the hash map if it does not exist

Example 3

private _array = _hashmap getOrDefault [_key, [], true]; // a new array will be created if it doesn't exist
_array pushBack _item; // _item will be added to the array (the one in the hashmap is updated by reference)

See also

getOrDefaultCall · HashMap · get