• 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 How do I save player location after switching room?

H

HenrikoNumberOne

Guest
Hi! I'm pretty new to Game Maker Studio and coding, but what I've managed to create this far is really making me motivated to want to learn more! I am currently trying to remake the original The Legend of Zelda for the NES in Game Maker Studio 1.4, but I am having a bit of trouble saving the player location after entering and exiting a dungeon / cave. What I want to achieve is having the player spawn right outside the cave they entered before on the over-world. If anyone has a (relatively) simple solution please tell me!

Thanks in advance.
- Henriko

Graphic Example:



Link enters cave


Link leaves the cave


What I want: Link spawns outside the cave


What currently happens: Link spawns at the default instance creation point, far away from the cave entrance.
 

obscene

Member
When the player leaves a room (room end event) save that room ID in a variable with something like from_room.

When you enter the next room, I assume your doorways have code which tells the player which room to go to. So check them all using "with" for a match. Example....

Code:
with (obj_doorway)
 {
 if room_destination == obj_player.room_from
   {
   obj_player.x=x;
   obj_player.y=y+64;
   }
 }
There's probably more to it than that but that's the principle.
 
H

HenrikoNumberOne

Guest
When the player leaves a room (room end event) save that room ID in a variable with something like from_room.

When you enter the next room, I assume your doorways have code which tells the player which room to go to. So check them all using "with" for a match. Example....

Code:
with (obj_doorway)
 {
 if room_destination == obj_player.room_from
   {
   obj_player.x=x;
   obj_player.y=y+64;
   }
 }
There's probably more to it than that but that's the principle.
Thanks a lot! I will try it out.
 
H

HenrikoNumberOne

Guest
Alright, after looking into the code and thinking about what I'm coding, I noticed that I do not have code which tells a default generic "objDoorway" what room to go to. I have made separate "objDoorway" objects, one per entrance and one per exit for every cave and dungeon (though I have only coded two doorways yet, there are currently two objects per cave which switches rooms, "obj.event_cave_enter_sword_1" and "obj.event_cave_exit_sword_1"). They only tell using drag and drop;

Code:
//Cave Enter Object

if collision(obj_Link) = true
   {
   room_goto(rm_overworld_v1)
   }

//Cave Exit Object

if collision(obj_Link) = true
   {
   room_goto(rm_cave1)
   }
}
I'm sure that code isn't correct because it's drag and drop originally, but that's the base concept.

So I assume that this code;
Code:
with (obj_doorway)
...does not actually work with the way I have it set up right now, because every doorway is a different object. What should I do to make it work? Should I make a generic obj_Doorway object and make it take me to the correct cave by using some kind of coordinate system or near-other-object system? If not, please tell me if I got all of this wrong.

Screenshot of the room_switch_events objects group


- Henriko
 
H

HenrikoNumberOne

Guest
I handle doors like I explained in this post a while back.
That sounds good, but I'm a bit confused about that fact that I have to set certain coordinates for every single door event? How am I supposed to get the specific coordinate of that door?
 
H

HenrikoNumberOne

Guest
I check the entry point's coordinates in the room editor. Unless you keep shifting the entry point around, you only need to do this once for each door.
Thank you, you're a savior! Everything works perfectly now! :)
 
Top