ds_map_default_value
Returns the value of a key from a given map, inserting a default value into the map if the key does not yet exist.
map = ds_map_create();
map[? "Hello"] = "World";
map[? "Goodbye"] = "Cruel World";
A = ds_map_default_value(map, "GML", "Scripts"); // A == "Scripts"
B = ds_map_default_value(map, "Hello", "I Love You"); // B == "World"
// resulting map:
// {
// GML: "Scripts"
// Hello: "World"
// Goodbye: "Cruel World"
// }
- ds_map_default_value(map, key, val)
- Returns the value of a key from a given map, inserting a default value into the map if the key does not yet exist.
COPY/// @func ds_map_default_value(map, key, val)
///
/// @desc Returns the value of a key from a given map,
/// inserting a default value into the map if
/// the key does not yet exist.
///
/// @param {map} map map data structure
/// @param {any} key key in the map
/// @param {any} val default value to insert
///
/// @return {any} value for the key
///
/// GMLscripts.com/license
function ds_map_default_value(map, key, val)
{
if (!ds_map_exists(map, key)) {
ds_map_add(map, key, val);
return val;
}
return ds_map_find_value(map, key);
}
Contributors: RaniSputnik
GitHub: View · Commits · Blame · Raw