Legacy GM [SOLVED]Wierd file save/load error

pixeltroid

Member
So I have an opening menu that lets player start a new game or continue from the last room he was in. The games save and load system saves the status of items like dead bosses, opened doors etc. All good so far.

The problem is that after playing a few rooms, and I exit to the menu screen and select "start new game", I restart from level 1, but the game still remembers the saved items mentioned above.

How do I make it so that when I select "start new", the game forgets everything and starts afresh?

Here's my save game script:

Code:
with (argument0) {
ini_open("save.ini"); 
 roomAlias = "T1" //default room
 
    if (room=room_T1) roomAlias = "T1"
    if (room=room_T2) roomAlias = "T2"
    if (room=room1A) roomAlias = "1A" //and so on

   ini_write_string("SaveFile1", "LoadedRoom",roomAlias);//save it as ini file
 
    var player = instance_find(obj_player, 0);
    ini_write_real("SaveFile1", "playerx", global.checkpointx);
    ini_write_real("SaveFile1", "playery", global.checkpointy);
 
  
//bosses
    ini_write_real("SaveFile1", "boss_killed1",global.boss_killed[1]);
    ini_write_real("SaveFile1", "boss_killed2",global.boss_killed[2]);
 
//doors
    ini_write_real("SaveFile1", "door_opened0",global.door_opened[0]);
    ini_write_real("SaveFile1", "door_opened1",global.door_opened[1]);
  
//keys
    ini_write_real("SaveFile1", "keys",global.keys);
    ini_close();
}
Here's my load game script:

Code:
if file_exists("save.ini")
{
    ini_open("save.ini");
    LoadedRoom=room_T1; //default room
    roomAlias=ini_read_string("SaveFile1", "LoadedRoom", "T1"); //sorry i fix this code
    if (roomAlias=="T1") LoadedRoom = room_T1
    if (roomAlias=="T2") LoadedRoom = room_T2
    if (roomAlias=="1A") LoadedRoom = room1A
    
  instance_find(obj_player, 0);
  playerx=ini_read_real("SaveFile1", "playerx", 10);
  playery=ini_read_real("SaveFile1", "playery", 10);
    
   //bosses
    global.boss_killed[1] = ini_read_real("SaveFile1", "boss_killed1", 0);
    global.boss_killed[2] = ini_read_real("SaveFile1", "boss_killed2", 0);
  
 
    global.door_opened[0] = ini_read_real("SaveFile1", "door_opened0", 0);
    global.door_opened[1] = ini_read_real("SaveFile1", "door_opened1", 0);
  
 
    global.keys=ini_read_real("SaveFile1", "keys", 0);
 
    ini_close(); 
 
    instance_create(playerx, playery, obj_player);    
 
    room_goto(LoadedRoom);
}
else
{
    //do nothing
}
Here's my menu script from where I can access "start new game" or "continue"

Code:
switch(mpos)
{   case 0:
     room_goto(room_start); // START NEW GAME
     break;
    }

   case 1:
    {
       scr_loadgame(); //LOAD GAME AND CONTINUE
       break;
    }


case 2:

    { 
        break;
    }

case 3:
    {
           game_end(); //QUIT GAME
     
    }
}
Can someone tell me what I must do to start a new game afresh and make the program forget everything it has saved as per the load game script?

NOTE: This problem does not occur if I close the game window and reopen it and select "Start new game"
 
Last edited:

SeraphSword

Member
It seems like the issue is in the code you are using to quit to menu. It should probably destroy any non-essential objects (anything you don't need to actually make it to the menu) or reset all changed values. Alternatively, you could have a second .ini with your default starting values, and just read from that whenever pressing "Start New Game".
 

pixeltroid

Member
It seems like the issue is in the code you are using to quit to menu. It should probably destroy any non-essential objects (anything you don't need to actually make it to the menu) or reset all changed values. Alternatively, you could have a second .ini with your default starting values, and just read from that whenever pressing "Start New Game".
I need to quit to menu before I can quit to desktop. So erasing values when quitting to menu would only make me restart from the first room when I select "continue".

Is there a way to delete the ini file that stores the values when I select "start new game" from menu?
 
P

ponotte

Guest
when new game is pressed, make it save "fresh/zero" values over the saved ones, and then load the save.
or if you want fresh savefile, if the ini file exists, delete it and create new one and if not, just create one.
 

pixeltroid

Member
@SeraphSword

How do I do what you suggested? What would the code look like?


@ponette

I tried

Code:
if file_exists("save.ini")
   {
   file_delete("save.ini");
   }
but its not working!
 

Yrbiax

Member
Is your room persistent? I had similiar problem, so I put: room_persistent = false; at end of level to make sure levels are cleared.
 

SeraphSword

Member
The .ini for default values would work exactly like your normal save and load .ini.
You just give it a different name (so defaults.ini or whatever instead of save.ini), and instead of just going to the main room on new game start, you use your load game code with that. So you use the exact same code to Start New Game as you do for Continue Game, just pointing at different files. You never write anything to defaults.ini, you just have it as part of your included files.
 

pixeltroid

Member
The .ini for default values would work exactly like your normal save and load .ini.
You just give it a different name (so defaults.ini or whatever instead of save.ini), and instead of just going to the main room on new game start, you use your load game code with that. So you use the exact same code to Start New Game as you do for Continue Game, just pointing at different files. You never write anything to defaults.ini, you just have it as part of your included files.
Hey. I didnt create a defaults.ini because I didnt know how to!

Instead I just copy pasted my default values (stored in an object thats activated during game launch) into a new script called "scr_resetvalues". Then I call the script from my menu when I select "start new game". Heres what my code looks like now!


Code:
switch(mpos)
{
case 0:
 scr_resetvalues(); //RESETS ALL VALUES
room_goto(room_start); // START NEW GAME
break;
 }

case 1:
{
scr_loadgame(); //LOAD GAME AND CONTINUE
break;
}
And it worked! :D Everything gets reset to default state.

Thanks for your help!
 
Top