• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Adding DS_LISTs to DS_MAPs [SOLVED]

I'm about to start writing the save/load system for my game using ds_maps and was wondering how I'd add an entire ds_list to a ds_map? The documentation says to use ds_map_write to store the list as a string and ds_map_read to transfer it to another data structure, but I'm getting this error when I run my code:

Code:
############################################################################################
FATAL ERROR in
action number 10
of Create Event
for object game_initializer_obj:

ds_list_read argument 2 incorrect type (16777215) expecting a String (YYGS)
 at gml_Object_game_initializer_obj_CreateEvent_10 (line 8) - ds_map_add( global.save_data, "Deck List 1", ds_list_read( decklist1_str ) );
############################################################################################
Code:
var decklist1_str = ds_list_write( global.deck1_list ); // Get the list of cards in the deck as a string
ds_map_add( global.save_data, "Deck List 1", ds_list_read( decklist1_str ) ); // Add the string to the ds_map
Why is it saying its expecting a string, but I thought using ds_list_write returns a string...?


EDIT: Opps! I forgot the id! Which is why I'm getting the error.
Code:
var decklist1_str = ds_list_write( global.deck1_list ); // Get the list of cards in the deck as a string
ds_map_add( global.save_data, "Deck List 1", ds_list_read( global.deck1_list, decklist1_str ) ); // Add the string to the ds_map
Still want to know if I'm going about this the right way though.
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
ds_list_read( global.deck1_list, decklist1_str )
This turns the string back into a list, so it's a data structure and not a string... If you want to write the string to the map, then you'd simply do:

Code:
var decklist1_str = ds_list_write( global.deck1_list );
ds_map_add( global.save_data, "Deck List 1", decklist1_str);
Then to read it again you'd do this:

Code:
var decklist1 = ds_list_create();
ds_list_read(decklist1, global.save_data[? "Deck List 1");
:)
 
This turns the string back into a list, so it's a data structure and not a string... If you want to write the string to the map, then you'd simply do:

Code:
var decklist1_str = ds_list_write( global.deck1_list );
ds_map_add( global.save_data, "Deck List 1", decklist1_str);
Then to read it again you'd do this:

Code:
var decklist1 = ds_list_create();
ds_list_read(decklist1, global.save_data[? "Deck List 1");
:)
Oh... I see. Thanks.
 
I do have another question though: is there way to add a ds_map to another ds_map? I'd rather have one big save file than two separate save files.
 

matharoo

manualman
GameMaker Dev.
is there way to add a ds_map to another ds_map?
Code:
bugs_ide = ds_map_create();
bugs_compiler = ds_map_create();
bugs_misc = ds_map_create();

gms2 = ds_map_create();
ds_map_add(gms2, "IDE Bugs", bugs_ide);
ds_map_add(gms2, "Compiler Bugs", bugs_compiler);
ds_map_add(gms2, "Misc. Bugs", bugs_misc);
Note that it'll add their IDs to the map, so they'll not be copied. The maps inside the map will be the same as the variables.
 

Simon Gust

Member
You can add a map the same you added the list just with map in the function name.
->
ds_map_write() and ds_map_read() to get the contents of the maps.
 
F

FluencyGames

Guest
Code:
bugs_ide = ds_map_create();
bugs_compiler = ds_map_create();
bugs_misc = ds_map_create();

gms2 = ds_map_create();
ds_map_add(gms2, "IDE Bugs", bugs_ide);
ds_map_add(gms2, "Compiler Bugs", bugs_compiler);
ds_map_add(gms2, "Misc. Bugs", bugs_misc);
Note that it'll add their IDs to the map, so they'll not be copied. The maps inside the map will be the same as the variables.

If you are adding ds_maps or ds_lists to a parent ds_map , you need to use ds_map_add_map() and ds_map_add_list().

This will preserve the nested data structures, allow you to dump to a string (ds_map_write()) or json string, and GM:S will delete the nested data structures when using ds_map_destroy().

If you do not use the ds_map_add_map() or ds_map_add_list(), GM:S will not know if your values are data structures or just a number. This will prevent GM:S from properly dumping the nested data structures.

Additionally, if adding ds_maps to a list, I always use ds_list_insert(list, 0, map) and then ds_mark_as_map(list, 0). Again for the same reasons above

Also, use json_decode() and json_encode() when saving your data. I know GM:S 1.4 used to dump the contents of the ds_maps and ds_lists differently between platforms.
 
K

Karam Al-Kofahi

Guest
hey sorry this is unrelated but how do i make posts? ive confirmed my email and everything but i cant seem to figure it out
 

matharoo

manualman
GameMaker Dev.
hey sorry this is unrelated but how do i make posts? ive confirmed my email and everything but i cant seem to figure it out
That's a post you made right there boi

To create a thread, go to any category (ex. Programming) and click on "Post New Thread" at the top right.
 
Top