• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

Having trouble with door objects

Taten

Member
Okay, I'm relatively new to programming so bare with me here. I was following heartbeast's tutorial on making a simple rpg, and am currently on ep.24(i think..?) I decided I wanted a grid system of rooms Link's Awakening DX style so I got to work trying to figure it out. I figured I could use the player_stats object to track the player's x and y position, and then put them into variables(last_x and last_y).
Using those I could line each side of the room with the door object, and have it so when the player runs to the edge of the room, it would use the last_x and last_y variables to place the player in the next room accordingly. Obviously since I'm writing this that is not how that went.
I've boiled down the problem to this singular thing: the door isn't updating the last_x and last_y variables, and simply goes with what I first initialized in the create event(it used to be 0 and 0 but that made the whole thing crash so I switched it to 32 and 32)
In the player_stats step event, I have this simple if statement running:
Code:
if (instance_exists(obj_player)) {
    last_y            = round(obj_player.y);
    last_x            = round(obj_player.x);
}
I have a draw gui event proving the Variable is updating, so what gives? Why won't the door use the updated variable?

Thank you,
taten

attached is a video showing my problem in action
 

EvanSki

King of Raccoons
Is the door even updating where the player is? for example
Code:
with(obj_player)
{
      x = 256;
      y = 326;
}

room_goto(rm_cake);
 

Taten

Member
No, I don't think. I have an object that tracks obj_player's x and y position, and then in the door's creation code it can go
Code:
new_room    = rm_1;
new_x        = (room_width - 32);
new_y        = obj_player_stats.last_y;
When the player collides with the door, in the collision event it says
Code:
//Go thru the door

if (room_exists(other.new_room)){
    room_goto(other.new_room);
    x = other.new_x;
    y = other.new_y;
}
 

NightFrost

Member
Room switches are not immediate. So what you're doing is repositioning the player in the first room, then the room switch happens, destroying the player, and in the new room the player spawns wherever you had put them in the room editor. One solution would be to make the player persistent, so coordinates are preserved between room switches. Another would be to position the player object in its create event to the coordinates you had saved. (Note that at game start there will be no 'position in previous room' so you need to set them to some default values.)
 
Top