ds_map_add

Adds the given value and associated key into the map.

Syntax:

GML Code Example

ds_map_add(id, key, val);


Argument Description
id The id of the map to add to.
key The key of the value to add.
val The value to add to the map.


Returns: Boolean


Description

This function should be used to add sets of key/value pairs into the specified ds_map. You can check this function to see if it was successful or not, as it may fail if there already exists the same key in the ds_map or you specify a non-existent ds_map as the id of the map to add to. Both keys and values can be made up of either integers or strings, so all of the following are acceptable:

GML Code Example

ds_map_add(map, 5, 1);
 ds_map_add(map, "level", 100);
 ds_map_add(map, 89, "hello world");
 ds_map_add(map, "fish", "good");
 

You can also add to a map using the accessor "?", as shown below:

GML Code Example

map[? 5] = 1;
 map[? "level"] = 100;
 map[? 89] = "hello world";
 map[? "fish"] = "good";
 



NOTE: Unlike other data structures in GameMaker: Studio this key will not go to the start (nor the end) of the ds_map, but rather it will just go into the ds_map somewhere.


Example:

GML Code Example

inventory = ds_map_create();
 ds_map_add(inventory, "hp potion", 1);
 ds_map_add(inventory, "gold", 100);
 

This will create a new map, assigning its id to the variable "inventory". It then adds two new keys to the map, "hp potion" and "gold", and sets their initial values as 1 and 100.


Back: DS Maps



No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here