• 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?

Hello,

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?

2E0100000300000001000000E20000003932303130303030303430303030303030313030303030303031303030303030373730303030303030303030303030303030303030303241343030313030303030303031303030303030363830303030303030303030303030303030303030303341343030313030303030303043303030303030363637323631364436353546373337303732363937343635303030303030303030303030303030303030433036373430303130303030303030423030303030303634364636463732354637333730373236393734363530303030303030303030303030303030303045303637343001000000E20000003932303130303030303430303030303030313030303030303031303030303030373730303030303030303030303030303030303030303332343030313030303030303031303030303030363830303030303030303030303030303030303030303341343030313030303030303043303030303030363637323631364436353546373337303732363937343635303030303030303030303030303030303030433036373430303130303030303030423030303030303634364636463732354637333730373236393734363530303030303030303030303030303030303045303637343001000000E200000039323031303030303034303030303030303130303030303030313030303030303737303030303030303030303030303030303030303033373430303130303030303030313030303030303638303030303030303030303030303030303030303033413430303130303030303030433030303030303636373236313644363535463733373037323639373436353030303030303030303030303030303030304330363734303031303030303030304230303030303036343646364637323546373337303732363937343635303030303030303030303030303030303030453036373430
 
A

Anthony Navarro

Guest
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.

Code:
    show_debug_message('-------------');     
    show_debug_message('Loading doors');
    temp_string = file_text_read_string(fileid);
    file_text_readln(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');
        file_text_close(fileid);
        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);
        file_text_writeln(fileid);
        file_text_close(fileid);
        fileid = file_text_open_read('CHUNKS\'+argument0+'.chunk');
    }
    //if we do, create doors from the list
    else
    {
        //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;
            }
            ds_map_destroy(temp_map);
        }     
    }
    file_text_close(fileid);
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.
 

jo-thijs

Member
Are you sue this line is correct?
Code:
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?
 
Top