SOLVED Looping through stages of a Level Editor

ome6a1717

Member
Hi,

I'm trying to figure out why something isn't working. Long story short, I've built a level editor that saves a compressed buffer to a .bat file that can be loaded into my main game. Each room in the level editor is a different level. I'm trying to figure out a way to do a "save all" command that loops through each level, and saves the bat file.

How I'm doing this; once I trigger the save all command, it goes to the first stage. I have a Room Start event on a persistent object that sets an alarm[0] = 10. That alarm contains this code:

GML:
var file = get_save_filename("bat|*.bat",room); // get save location

save_current_stage(file) // function which creates the buffer and saves the file
alarm[1] = 50; // use this alarm to go to the next stage
Then in the alarm[1] I just have "if you've set to save all, room_goto_next()".

However, for some reason this doesn't seem to be working. I've even tried taking out the get_save_filename and save current stage and literally just left in the "room_goto_next" to see if it would travel through each of the stages, but it only goes to the next one and stops there. What's even more strange is that if I put back the alarm[0] code, it saves the first stage, and then immediately tries to save it again (almost as if it's reloading the stage). Are persistent objects recreated in each room and re-trigger the create event?

I've done a search all for any room_goto code that I'm missing thinking that was the problem, but to no avail. I'll post save_current_stage function below in case that helps, but I'm pretty sure that's not the issue at the moment.

GML:
function save_current_stage(_savename) {
    var file = _savename //get_save_filename("bat|*.bat","")
        if file != "" {
            write_tm_to_grid();
            write_tm_to_index_grid();
            write_hazard_tm_to_grid();
            write_secret_tm_to_grid();
                   
                   
            var _b = buffer_create(256,buffer_grow,1);
                   
            // grid
                //var map = base64_encode(ds_grid_write(grid));
                buffer_write(_b,buffer_string,ds_list_write(grid));
                buffer_write(_b,buffer_string,ds_grid_write(index_grid));
                buffer_write(_b,buffer_string,ds_list_write(haz_list));
                buffer_write(_b,buffer_string,ds_list_write(secret_list));
                       
                       
            // bounding box
                buffer_write(_b,buffer_u16,o_camera_bounds.bbox_left);
                buffer_write(_b,buffer_u16,o_camera_bounds.bbox_right);
                buffer_write(_b,buffer_u16,o_camera_bounds.bbox_top);
                buffer_write(_b,buffer_u16,o_camera_bounds.bbox_bottom);
                   
            // player spawn pos
                buffer_write(_b,buffer_u16,o_p_spawn.x);
                buffer_write(_b,buffer_u16,o_p_spawn.y);
                       
            // enemies
                var _enemy_list = ds_list_create();
                       
                with(_o_enemy_parent) {
                    ds_list_add(_enemy_list,[type,x,y,image_xscale]);
                }
                       
                buffer_write(_b,buffer_string,ds_list_write(_enemy_list));
                       
                ds_list_destroy(_enemy_list);
                       
                       
            // hazards
                var _hazard_list = ds_list_create();
                       
                with(_o_hazard_parent) {
                    ds_list_add(_hazard_list,[type,x,y,image_angle,link]);  
                }
                       
                buffer_write(_b,buffer_string,ds_list_write(_hazard_list));
                ds_list_destroy(_hazard_list);
                   
            // exits
                       
                buffer_write(_b,buffer_u16,_o_exit_parent.x);
                buffer_write(_b,buffer_u16,_o_exit_parent.y);
                buffer_write(_b,buffer_u8,_o_exit_parent.image_xscale);
                buffer_write(_b,buffer_u8,_o_exit_parent.image_yscale);
                       
            // savable heroes
                   
                var _save_list = ds_list_create();
                   
                with(o_savable_hero) {
                    ds_list_add(_save_list,[hero,x,y]);//,rng]);
                }
                       
                       
                buffer_write(_b,buffer_string,ds_list_write(_save_list));
                       
                ds_list_destroy(_save_list);
                       
                       
                       
            var map_cmprs = buffer_compress(_b,0,buffer_tell(_b));
                buffer_save(map_cmprs,file);
        }
}
 
Last edited:

ome6a1717

Member
UPDATE: Figured it out myself - I was trying to do if room >= first_room, but apparently you cannot order rooms like that, so I just made a ds_list of the rooms.
 
Top