GameMaker: Studio

GameMaker: Studio

View Stats:
Torch Bearer Jul 12, 2019 @ 5:44pm
room next and room previous
hey all, coded an elevator in my game , successfully goes to the next level when i press a button and closes the doors.

any advice on how to get to the previous room by pressing the same button? or should i just make a new object?
< >
Showing 1-4 of 4 comments
Torch Bearer Jul 12, 2019 @ 6:00pm 
...furthermore, how do i save the position of the player to the elevator when I return instead of beginning where I originally start

edit: marking my rooms as persistent causes it to crash

Last edited by Torch Bearer; Jul 12, 2019 @ 6:05pm
Zappy Jul 13, 2019 @ 12:42am 
Originally posted by High Ping:
- any advice on how to get to the previous room by pressing the same button? or should i just make a new object?
This really depends on how you have set things up. One thing that you could do would be to make it use the room_goto(numb)[docs.yoyogames.com] function to go to a specific room, with "numb" being a custom variable (such as "room_to_go_to"), while you then use the Room Editor to give the elevator object instance "creation code", that simply does something like...
room_to_go_to=room_tower_level; //Make this elevator go to the tower level
You can then use creation code on the elevator instance in the other room, setting "room_to_go_to" to the room at the other end of the elevator.


So, in other words, make the elevator object use room_goto(numb) to go to a specific room, and use instance creation code in the Room Editor to set a custom variable for the elevator object instance, to decide which specific room to go to.


Originally posted by High Ping:
...furthermore, how do i save the position of the player to the elevator when I return instead of beginning where I originally start -
One of the ways (by no means the only way) that you could do that would be to have a persistent object in the first room of the game (which should be a simple one-off "initialization" room or such, which'd instantly then go to a menu room or the first level afterwards), called "object_system" or "obj_system" or such (I always do that whenever I make a GameMaker: Studio thing). (The Create Event of that object can be set to go to the next room.)

Then you can have that "system" object store a custom checkpoint variable or such, which can determine where the player object should start.

For example, you could use the Room Editor to add creation code to the player object instance, doing something like...
if object_system.custom_checkpoint=="Room Tower Bottom, Checkpoint End Elevator" //If the current checkpoint is set to be the end elevator of this room... { x=1032; //...move the player to the end of the room... y=520; custom_facing_direction=-1; //...and face to the left instead of the right }
And then you can have the elevator object set "custom_checkpoint" to a blank string (""), followed by making it do the following when going through the elevator:
object_system.custom_checkpoint=custom_checkpoint; //Set the player checkpoint
And then you can use creation code to set the elevator object instance's "custom_checkpoint" variable to the appropriate thing. This will make the elevator set a checkpoint when going through it.


So, in other words, make a persistent "system" object, have that object store a custom checkpoint variable, have the elevator set that variable, and have the player check for that variable to make the player spawn somewhere else in a room.
Last edited by Zappy; Jul 13, 2019 @ 12:43am
The Winter Bud Jul 13, 2019 @ 10:06am 
https://www.youtube.com/watch?v=bNsfbCDL2XA

the video shows a nice way to save to file information you would like to have when the player plays the game. You could have the player write down where they were when they left. And then load up the location when they return. Maybe more than what you need. Not sure what you got built and what you plan on building in the future.
Torch Bearer Jul 14, 2019 @ 5:17pm 
Originally posted by The Winter Bud:
Thank you for your replies, I stumbled across the method that Zappy suggested, I felt like it was more natural because I'm still learning GML so I managed to get there through trial and error ha! However, I've noted your suggestion because I feel that when my game is larger then I will absolutely need to integrate this into the system. I haven't seen or understand all of Popes material just yet as I am learning through experimenting at the moment but I will definitely take this into account when the time to cross that bridge comes, thank you. BTW, ds grids and lists confuse me heh....



Originally posted by Zappy:
Originally posted by High Ping:
Thank you for your contribution, I never had room_to_go_to on my radar up until this point, that is a very interesting way to transition between levels. I'll need to keep this in mind!

Funny that you mention it, after a few hours of experimenting I ended up doing exactly as you suggested with having an object system create an object that pushes me into the next room so to speak. I'm really proud to say that now I have a functioning elevator! The door opens and closes, reacts to button press, and transitions back and forth between levels while making all the necessary noises. Even with some elevator music! Thanks to both of ya
Last edited by Torch Bearer; Jul 14, 2019 @ 5:22pm
< >
Showing 1-4 of 4 comments
Per page: 1530 50