• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Restart a Persistent Room

A

arirish

Guest
I am maybe a third to a halfway done with level layouts for my game and I've hit a snag. I added a new element in the current set of rooms - a sort of basic puzzle - which, if the player does something wrong, can make the room impassable. So I thought to add another object which, when interacted with, would restart the current room. However, I've quickly discovered it's not going to be that simple.

I tried this simple bit of code (using a key press event for now, for testing purposes):
Code:
room_persistent=false
room_restart();
obj.x=startx
obj.y=starty
And in my control object's Room Start event I added:
Code:
room_persistent=false
startx=obj.x
starty=obj.y
And that all works fine. Enemies and items respawn, and my player returns to the start of the room. I thought I had it fixed, until I collected an object and then restarted the room. The object remains in my inventory as well as respawning in the room, and any benefits it confer (ie variables changed) remain conferred.

So, what I need to figure out is how - without manually recording the state of all variables one by one on room start - to make sure this doesn't happen. A way to reset the room - and the character and variables - to how they were when they entered the room. Right now the only way I can see is to do similar to I did with x and y positions, and save them all on room start, but there are quite a lot and it could easily get very messy.
 
I

InfraViolet

Guest
You could try saving the game when the player enters the room and loading that save when the player hits the switch.
 
A

arirish

Guest
Thanks for replying. I did briefly think of that, but didn't really want to start messing about with external files for this. If I can't think of anything else - or there are no other viable suggestions - I'll probably go that route.
 
I

InfraViolet

Guest
Maybe you can create a deactivated duplicate of the player object (with instance_copy() ) when the room starts. Then when you restart the room, destroy the active player object and activate the copy.
 
A

arirish

Guest
Oh! That sounds interesting. I'll look into that and report back, thanks!
 

CMAllen

Member
You could also keep a copy of the base states of all the pieces the player can interact with in that 'reset object.' Then it's just a matter of using that information to tell all the other pieces what state they should be in. Unless I'm misunderstanding the extent of the ways the player can interact with the room in question.

Alternatively, if you allow the player to move back to the previous room, setting this puzzle room to be non-persistent means that it will automatically reset if the player leaves and comes back in. Then, when/if the player correctly solves the puzzle, you can set the room to persistent, and it will remain solved.
 
G

GM029

Guest
How are you tracking what is stored in the inventory? I usually do that with global variables. If you're using global variables the room persistence setting won't do anything to the global variable, you will have to change it yourself.

I also usually use a global variable to tell which major objects have already been collected, then use code to spawn it based on if I've collected it or not already.

Something like:

if (!hasgoldencrown)
{
instance_create(obj_goldencrown, 30, 500);
}

Rather than putting it directly in the level using the room editor.

That'll stop it from re-spawning if you've already collected it.
 
Last edited by a moderator:
A

arirish

Guest
Eh, so I tried a couple of your suggestions and nothing was working cleanly enough, and I kept realizing further complications, so I'm going with a different approach: I'm just going to design my rooms so that no collectible items are in rooms with restart blocks. Haha. I would've liked a more robust solution, and I'm sure I've been given one with enough working out, but this'll work too.

So thanks much to all who helped. Maybe eventually I'll come back to figure this out properly.
 
Top