"New Game" game_restart not working

P

polartropics

Guest
So i have a main menu, and a few test levels, i also have a save and load feature. it works fine, except the whole game is persistent. its an RPG game so when i load the stats i had when saved and the room i was in when saved becomes the current room and stats. It all works fine except when you create a new game from the main menu.

My thinking was when you press "New Game" you need to reset the whole game, i looked this up and the code for this is rather straight forward game_restart();. except it does literally nothing. the current room is not the starting room, the stats are the same and all the killed enemies are still gone. my solution was to reset the stats and make the current room = starting room, this works except, if you've killed any enemies or collected anything, then theyre still dead or missing because every room is persistent. I thought game_restart(); wouldve solved this but it doesnt. Nnow its looking like im either going to write a huge slow code;

rm_firstroom.persistent = false;
room_restart();
rm_firstroom.persistent = true;
rm_secondroom.persistent = false;
room_restart();
rm_secondroom.persistent = true;

...cont. for a hundred levels

and i really dont think this is the best way of going about this
so more likely im going to have to make the main menu inaccessible from the pause menu so if you want to start a new game, you need to manually exit and restart the game. and make the "New Game" button just send you to the starting room. Save and Load are in the pause menu so you could load at anypoint but you cant start again without exiting and starting the game from windows and that sucks.

Any ideas?
 

TheouAegis

Member
No, when you start a new game from the menu like that, all you are doing is declaring all variables with their initial value. Whatever you were doing 2 start a game in the first place, you do that for every time you call the new game option. Game restart is ultimately for just debugging your game because it is a crappy function.
 
P

polartropics

Guest
No, when you start a new game from the menu like that, all you are doing is declaring all variables with their initial value. Whatever you were doing 2 start a game in the first place, you do that for every time you call the new game option. Game restart is ultimately for just debugging your game because it is a crappy function.
oh, so is there any way then to reset all variables to their initial value, like resetting the persistent rooms to have all enemies alive again and somehow saving and loading persistent room states. (i.e. kill 1 enemy, save. create a new game. both are alive, load 1 is dead)
 

TheouAegis

Member
Oh you're using persistent rooms.... First create an empty room and put it at the very end of your resource list. Make a global variable to specify that you want to reset all the rooms. In a persistent controller object, when New Game is clicked you set your variable to true and then you loop through all the rooms that are persistent and call room_set_persistent(roomID,false) to tell each room to clear itself. Then use room_goto_next() to go to the next room in the resource list. In the Begin Step event of your persistent controller, check if your global variable is true; if it is, check if the current room is the last one in your resource list. If it isn't, go to the next room; but if it is the last room, go to the name entry room or whatever. Now, make sure the last room is not persistent (it's the empty room you made). Go to the Settings tab and click Creation Code to bring up the room's code editor. Now loop through all the rooms that are supposed to be persistent and set them back to persistent using room_set_persistent(roomID,true). Then that should take care of all t hat.
 
Top