• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

[Solved] ds_map strings in ds_lists saved to file. Is there an issue?


It's late here and I am giving up on debugging this issue for the night. Just wondering if perhaps there is a known issue when writing ds_maps to strings, adding those strings to a ds_list, turning that ds_list into a string and saving it to a file... and then reversing this process to load the ds_list and ds_maps back into a game (I realize this is space inefficient but I am not optimizing yet)?

I keep getting back an empty ds_list, despite the entry in the file being rather long?


Anthony Navarro

I'm not sure it will be a problem as I have never done this, but why not just write the map string to the file and cut the list out altogether?
Can you give us the code you're using?
There are quite a few moving parts to this, which is why I didn't just write a big post asking for help. Maybe it is just some oversight. My last two issues have been just small oversights. Anyway, here is the code for loading and then placing door objects. I output some debugging information in a draw GUI event, so I know when this gets loaded, ds_list_size(global.doors) always ends up being 0. I know the ds_list as created isn't zero, since I create it in my map editor and the list size reflects the number of entries correctly.

The if statement is a failsafe as my file format is slowly evolving. I know it doesn't trigger due to debugging output in the compile window.

    show_debug_message('Loading doors');
    temp_string = file_text_read_string(fileid);
    //if we do not already have a door data structure, create one
    if (temp_string == '')
        show_debug_message('no door list present; creating empty list and appending');
        fileid = file_text_open_append('CHUNKS\'+argument0+'.chunk');
        temp_list = ds_list_create()
        temp_string = ds_list_write(temp_list)
        file_text_write_string(fileid, temp_string);
        fileid = file_text_open_read('CHUNKS\'+argument0+'.chunk');
    //if we do, create doors from the list
        //global.doors = ds_list_create();
        show_debug_message('Loading doors...')
        ds_list_read(global.doors, file_text_read_string(fileid));
        show_debug_message('Doors list size is '+string(ds_list_size(global.doors)));
        for (i = 0; i < ds_list_size(global.doors); i += 1)
            show_debug_message('Trying to place a door...');
            temp_map = ds_map_create();
            ds_map_read(temp_map, ds_list_find_value(global.doors, i));
            frame_sprite = ds_map_find_value(temp_map, 'frame_sprite');
            door_sprite = ds_map_find_value(temp_map, 'door_sprite');         
            w = ds_map_find_value(temp_map, 'w');
            h = ds_map_find_value(temp_map, 'h');
            with (instance_create(w * 16, h * 16, obj_door))
                frame_sprite = other.frame_sprite;
                door_sprite = other.door_sprite;
I'm not sure it will be a problem as I have never done this, but why not just write the map string to the file and cut the list out altogether?
This would be messy, require me to keep track of how many doors in a separate variable that would need to be stored and read, would complicate looping through all doors, would require dynamically adjusting how I read my file format based on how many door entries there are... Essentially it makes everything more complex and messy, especially since there will be more lists like this one for other object types. I did something like you suggested in an old version of my system, but it quickly becomes apparent that as complexity increases the chance for error increases. I'd like to get this to work and, if not, then try a work around (unless there is some simpler system than this).

As a note, I've also used .inis with dynamic section names for this kind of thing. While that system is clean, I end up with wayyyy too many files for my liking.


Are you sue this line is correct?
ds_list_read(global.doors, file_text_read_string(fileid));
Don't you want to read temp_string, instead of the line below temp_string in the file?