• 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!

GameMaker How do I have multiple doors in one room that allow backandfourth travel?

P

Political Gangster

Guest
Currently, my character can go through a transition space when I'm standing over it and hit w, then I'm in a new room. But, when I want to head back to the first room my character, starts back at the starting position and not where he would in real life at the door he went through to get into the second room. I've tried messing around with the persistence and the creation code of my Trigger area and had no real progress. Please help me! Hope that all made sense.
 
E

Ephemeral

Guest
You probably want to store the destination coordinates for the destination room in the door instance in the room you're leaving from. When you hit W, the door's code should pass: the destination room id, the target x in that room, the target y in that room, and optionally, the direction to be facing; all to a separate persistent controller object which changes the room and then places the character.

There are several ways to implement this. If you don't already have a persistent controller object in which this code would naturally fit, you can make an object specifically for this purpose, then:
1) Door's target variables are set in its Instance Creation Code
2) Door code, when you hit W, creates an instance of the persistent room-changer object.
2a) room-changer sets its first alarm to 1 in its create event
3) Door code sets the variables in the room-changer instance to match its target variables.
4) room-changer changes the room in its alarm event (do not put room_goto() in the create event; due to the order GMS2 executes events, I suspect doing so would guarantee a game-crashing error)
5) because the room-changer object is set to persistent, the room-changer instance still exists in the new room
6) room-changer places your character according to target variables, in its room start event
7) room-changer deletes itself

Alternatively, you can just use global variables to store the target variables instead of an object, and have your character re-place itself in its own room start event, but that will limit you in other ways.
 
D

DarthTenebris

Guest
If I'm understanding you correctly, you are trying to have a player exit the room at coordinates (x, y), and when you return you would like the player to be placed at (x, y) instead of the original coordinates?

If so, while this isn't really a solution, I would like to give my suggestion, try having a single large room with a view.
To start things off, everything outside the view is deactivated, so no resources wasted. When you switch rooms, instead of literally switching rooms, you can move the view. Then deactivate the previous view. When you return to the previous room, switch the view again, and since you aren't really switching rooms, you still have your instance variables intact and can use that to load the coordinates the player was at before you switched the view.
Probably won't work right off the bat, but this is just an idea of how you can do it (this is how I handled a pause menu in my game).
Hopefully you get the idea.

Well if not, another method I can think of is having a persistent object in the "boot room" of your game (and nowhere else, or it will screw up) and store coordinates the player was at before switching rooms there. When you reload that room, get the variable in that object.
Yet another method I can think of is using global variables, as (I think) they're not affected by the presence of a certain object / instance, and can be accessed anywhere by anything.

Hope it made sense, and hope I helped :)
 
Top