This function sets the value of a key within a given DS map.
You supply the DS Map value (as returned by the function ds_map_create), then give the key you want to set and the value to set it to. If the given key does not exist then it will be created for you and set to the value.
Since the function doesn't return anything, you should use the function ds_map_replace to check if the key value has been replaced or a new key has been created.
TIP The key isn't limited to strings and can be of any type, including a struct.
NOTE This function is the same as using the DS map accessor to set/create a map key/value pair.
ds_map_set(id, key, value)
Argument | Type | Description |
---|---|---|
id | DS Map | The id of the map to use. |
key | Any | The key to set. |
value | Any | The value to set the key to. |
N/A
struct_key = {a: 10, b: "Some text"};
map_key_value_pairs = ds_map_create();
ds_map_set(map_key_value_pairs, "score", "the value belonging to the string key");
ds_map_set(map_key_value_pairs, 8, "The value belonging to the real number key");
ds_map_set(map_key_value_pairs, struct_key, "The value for the struct key");
show_debug_message(map_key_value_pairs[? "score"]);
show_debug_message(map_key_value_pairs[? 8]);
show_debug_message(map_key_value_pairs[? struct_key]);
The above code first creates a basic struct struct_key. It then creates a new DS map using ds_map_create and stores it in a variable map_key_value_pairs.
Next, three different keys in the DS map are set using ds_map_set, each having a different type: the first key is a string, the second a number and the last one a struct.
Finally, the three values are looked up using the DS map accessor ? and shown using show_debug_message.