Problem with saving level (room) - ini file

artem123

Member
Hi.

I am trying to implement a system where the last level (room) will be saved. Say, a player reached level 15, it will be automatically saved if the player clicks a next button. And then when the player exits the game, reopens the game and clicks the play button, the player will be loaded in the level 15 room. Actually this is similar to this question: https://forum.yoyogames.com/index.php?threads/solved-game-save-level-select-screen-conflict.47304/ BUT I am trying to do it in ini, I wanted to do it in ini and avoid using file_ .... I tried to implement it in ini but a problem exists when closing the game and playing it again. The level is not saved after you close and re-open the game.

Code:

Save object - This is a persistent object placed in my init room, event Room start:

GML:
if (file_exists("save.ini")) file_delete("save.ini")
ini_open("save.ini")
ini_write_real("save1", "room", global.last_level)
ini_close()
Load object - This is a persistent object placed in my init room, event Game start:

GML:
if file_exists("save.ini")
{
    ini_open("save.ini")
    global.last_level = ini_read_real("Save1", "room", 1)
    ini_close()
}
Play button - placed in menu room, I think this does not matter since this only selects the room where the last level is saved.

GML:
switch (global.last_level)
{
case 1:
room_goto(rm01)
break;

case 2:
room_goto(rm02)
break;

case 3:
room_goto(rm03)
break;

case 4:
//... until case 20  (since my game has 20 levels)
}
Again, the problem is: If a first time player plays the game, it is working as intended. However, if a player quits the game and reopens the game, the level is not saved and is back to Level 1.

Thank you for your insights.
 

Yal

šŸ§ *penguin noises*
GMC Elder
You're writing to section "save1" but reading from section "Save1". Since that doesn't exist (they're case-sensitive) you always get the default value when reading the file.
 

artem123

Member
You're writing to section "save1" but reading from section "Save1". Since that doesn't exist (they're case-sensitive) you always get the default value when reading the file.
Lol, that solved my problem. Forgot about that case-sensitive thing. Stupid me.
Thanks anyway.
 
Top