GML room_goto constantly goes to the wrong room (saving with ini)

hana0rain

Member
This is how it is saved;

GML:
        ini_open("save.ini");
    
        ini_write_string("room", "currentRoom", room_get_name(room));
    
        ini_close();
This is how it is loaded;
GML:
        ini_open("save.ini");
     
        roomLoad = ini_read_real("room", "currentRoom", mainMenu_Room);
     
        ini_close();
     
        room_goto(roomLoad);
I am checking the ini file and it saves the correct room name but when I load I always go to the same wrong room.
I've put a save/load object at the beginning of the game and made it persistent.
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
What is the value of roomLoad after reading to it from the file? What is the value of the ID of the room you're saving the game in? Do they match?

Which room does this code cause you to go to? Is it always the same room, is it seemingly random, or does it depend on which room you save the game in?
 

hana0rain

Member
What is the value of roomLoad after reading to it from the file? What is the value of the ID of the room you're saving the game in? Do they match?

Which room does this code cause you to go to? Is it always the same room, is it seemingly random, or does it depend on which room you save the game in?
Yes and yes, I am checking the ini file and it saves the correct room but when I load I always go to the same wrong room.

could it be because of how I name my rooms
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
Hang on... I missed this the first time. You're saving the name of the room. Save its ID instead. As in, save room, not room_get_name(room). Rooms are identified by their ID, not their name.
 

hana0rain

Member
Hang on... I missed this the first time. You're saving the name of the room. Save its ID instead. As in, save room, not room_get_name(room). Rooms are identified by their ID, not their name.
Thank you very much! It fixed the issue. Can't thank you enough.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
I wouldn't save things by ID... Sorry, but IDs can (and will!) change. Your instinct to save the room name is correct, and all you need to do to reload it is to get the name string from the INI file and then use "asset_get_index()" to get the corresponding room ID at run time. This way you never have to depend on the actual ID value and the room will always be correct as long you as you don't change the room name.
 
Top