Invert GMLscripts.com

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/// 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.
//
//      map         id of the map to modify
//      key         key in the map
//      val         default value to insert
//
/// GMLscripts.com/license
{
    var map, key, val;
    map = argument0;
    key = argument1;
    val = argument2;
    if (!ds_map_exists(map, key)) {
        ds_map_add(map, key, val);
        return val;
    } else {
        return ds_map_find_value(map, key);
    }
}

Contributors: RaniSputnik

GitHub: View · Commits · Blame · Raw