Restart a persistent room

Jorg Gjer

Member
Split from here ~Tsuk

Hi all. I have just the same problem.
There is a lot going on in the room. So to easy stop everying when pressing 'P' , I take a snapshot of the screen and bring it into the pause room.
When i hit P again i just goto the room , and everything is running as normal.
Works wonderfully.

But now I want to add the option to restart the game.

I was hoping it was as easy as :
GML:
gameroom.persistent = false;
gameroom.persistent = true;
room_goto(gameroom);
This give fatal error when set back to true.

So I removed the line , and set persistante to true in the game room.

Then the room_goto , reports an error on the player object. I don't get it.

Why can't I go to the room after setting persistance to false ?


I feel GM allways has good solutions , so there should be a more easy way then storing all that is going on in the room.
Also I want to be 100% that all in the room is reset.


So i feel this case is not SOLVED


Would be happy if anyone can help.

Greeting
 
Last edited:

woods

Member
so long as this is inside your pause menu and not in teh bit that everything is paused.. it should restart the game.. you can swap out [game_restart()] with [room_goto()] should bring you to the begining of said room..

if (paused = true ) && (keyboard_check_pressed(vk_enter))
{
game_restart();
}


edit:
should ;o)
 

Yal

🐧 *penguin noises*
GMC Elder
Notably, the documentation on https://docs.yoyogames.com/source/dadiospice/002_reference/rooms/room_set_persistent.html points out that the only way to unset persistence is to go back to the room and turn off persistence while inside it, because even if you turn off persistence you'll still load the persisted copy the next time you enter the room... so that's what you're gonna have to do.

  • Create a new "unpauser" object
  • When pausing, create one of those before changing rooms
  • In its room start event, check the value of "global.unpause_action" and do different things depending on it - e.g. if you pick "restart the game", unset persistence and restart the game. It always destroys itself after it's done (so you don't stack up multiple if you pause several times)
  • In the pause menu, set global.unpause_action to the appropriate value each time you exit the menu, and always go back to the pause'd room.
 

Jorg Gjer

Member
Hi & Thank you for answers , but first I was not able to get it to work.

I try to do a soluton like Yal Sugesting.

The creation code of the gameroom now look like this.

GML:
room_persistent = true;

if(global.unpause_action == "restart"){
    global.unpause_action = "None";
    room_persistent = false;
    room_restart();

}
This is not working. I can see creation code is only run first time I start up.

But i moved the code to a setup object in the room, and now it is working.

Thank you so much for help.

Greeting Kaizen
 
Last edited:

Yal

🐧 *penguin noises*
GMC Elder
This is not working. I can see creation code is only run first time I start up.

But i moved the code to a setup object in the room, and now it is working.
Yes, Creation Code counts as "create event" scope (only runs the first time), not "room start event" scope (runs every time you enter the room, even if it's not the start) so this makes sense.
 
Top