ds_map_add_list

Adds a previously created ds_list to a given ds_map.

Syntax:

ds_map_add_list(id, key, value)


Argument Description
id The id of the map to use.
key The key for the added list.
value The id of the list to add.


Returns: N/A


Description

With this function you can assign a (previously created) ds_list to a key within the given ds_map. This function is designed for creating JSON compatible maps which you would then encode using json_encode and should only be used in conjunction with that functionality. If a ds_map has a list added in this way, destroying the parent map will also destroy the contained lists and free their memory.


Example:

var j_list = ds_list_create();
ds_list_add(j_list, health);
ds_list_add(j_list, lives);
ds_list_add(j_list, score);
var j_map = ds_map_create();
ds_map_add_list(j_map, "list", j_list);
var j = json_encode(j_map);
ds_map_destroy(j_map);

The above code will create a list and populate it with the various values of global variables. This list is then "nested" within a ds_map, and the map is then encoded into a JSON string, before the map is destroyed, removing it, and any lists it contains, from memory.


Back: DS Maps
Next: ds_map_add_map
© Copyright YoYo Games Ltd. 2018 All Rights Reserved