Transition Between Rooms Problem

Velocity

Member
Hey,

So I made a fake 3D game - kinda like Pokemon Blue, and I'm TRYING to transition between rooms by colliding with an object at the edge of my ROOM. Um, I ALREADY made my character and movement, and a collision situation between the character's collision mask and a barrier object - just to STOP him when he gets to a wall. But then I followed both Shaun Spalding's Persistent Levels tutorial, and Beyond Us Games Transition Rooms tutorial, BOTH on YouTube, to try to make the character transition to another ROOM when colliding with a WARP object. But it's not WORKING.

I made the WARP object,

obj_warp

Then I made a CREATE event, and set three variables:

var targetX, targetY, targetRoom ;

Then I made a COLLISION event with my character, let's call him obj_player. And I set his next room x and y location and the room_goto () command with a targetRoom variable.

obj_player.x = targetX ;
obj_player.y = targetY ;
room_goto(targetRoom) ;

Then I put the warp object along the top EDGE of the room, making sure it was actually IN the room, and covering the WHOLE top of the level. The width of the room is 880 and the HEIGHT is 1244. And then I double clicked the INSTANCE and clicked on Creation Code, and put in the FOLLOWING

targetX = 440 ;
targetY = 646 ;
targetRoom = room_2;

I made it so as not to transition back over the NEXT warp object, that I put at the BOTTOM of the NEXT room. The NEXT room is IDENTICAL to room_1. The PROPER targetY position should be WAY closer to the BOTTOM of the screen, but I'll set that later.

So for the warp object instance at the bottom of room_2, the Creation Code, is:

targetX = 440 ;
targetY = 640 ;
targetRoom = room_1;

And in my Player movement. I have obj_player. With a Collision mask, spr_collision_mask. With a Create Event, and the following code:

image_speed = 0;
image_index = 0;

Then I have a STEP event, with the following code:

image_speed = 0;

if(keyboard_check(ord("W"))){
if(!position_meeting(x,y-1,obj_barrier))
y-=1;
sprite_index = spr_player_up;
image_speed = .2;
key_up = true;

}
if(keyboard_check(ord("A"))){
if(!position_meeting(x-2,y,obj_barrier))
x-=2;
sprite_index = spr_player_left;
image_speed = .2;
key_left = true;
}
if(keyboard_check(ord("S"))){
if(!position_meeting(x,y+1,obj_barrier))
y+=1;
sprite_index = spr_player_down;
image_speed = .2;
key_down = true;
}
if(keyboard_check(ord("D"))){
if(!position_meeting(x+2,y,obj_barrier))
x+=2;
sprite_index = spr_player_right;
image_speed = .2;
key_right = true;
}

if(image_speed = 0)
{
image_index = 0
}

depth = -y;




So BASICALLY, the whole WARP function, or transitioning between rooms ISN'T working for me. If you could help me figure out how to transition rooms that would be great.

Thanks.
 

pixeltroid

Member
Hey, I don't have a solution and I don't know if your code is correct, but I too have experienced room change errors for no reason.

I had no idea why it wasn't working and was on the verge of giving up. But then I made a new project file and imported all the rooms and objects to it and for some reason it just started to work.
 

Slyddar

Member
Is your player persistent? And if so how is the player spawned? If they are dragged to the room in the room editor, everytime you return to that room, a new player instance will be created.

When you say it's not working, is there an error, or does nothing happen when you collide with the warp instance?

Have you tried placing a breakpoint in the player<>warp collision event, then running the debugger to step through the collision and see what happens?
 

Velocity

Member
Hey, I don't have a solution and I don't know if your code is correct, but I too have experienced room change errors for no reason.

I had no idea why it wasn't working and was on the verge of giving up. But then I made a new project file and imported all the rooms and objects to it and for some reason it just started to work.
Oh OK, that kinda sucks. But I'm glad it worked in the end.
 

Velocity

Member
Is your player persistent? And if so how is the player spawned? If they are dragged to the room in the room editor, everytime you return to that room, a new player instance will be created.

When you say it's not working, is there an error, or does nothing happen when you collide with the warp instance?

Have you tried placing a breakpoint in the player<>warp collision event, then running the debugger to step through the collision and see what happens?
Yes my player's persistent. He's NOT spawned. I dragged him into the room in the room editor.

There's no error. It just DOESN'T do anything when I collide with the warp instance.

"Have you tried placing a breakpoint in the player<>warp collision event, then running the debugger to step through the collision and see what happens?"

I don't know how to DO that...
 

Slyddar

Member
Even though this tutorial is in drag and drop, the concept is the same, so maybe it will help you. It seems to be similar to what you've already done, but it also addresses the problems you can get when using persistent objects and moving rooms.

You might see something that you haven't done yet which is not allowing your code to work.

 

Velocity

Member
Even though this tutorial is in drag and drop, the concept is the same, so maybe it will help you. It seems to be similar to what you've already done, but it also addresses the problems you can get when using persistent objects and moving rooms.

You might see something that you haven't done yet which is not allowing your code to work.

I WATCHED the video and it didn't really have anything that I could use to fix MY game. Um, it's still CLOSELY as RELATED to it though. And the guy in the video has AWESOME looking games. I'm FOLLOWING him now on YouTube.
 

Velocity

Member
Also check out this info on using the debugger. It's very useful for stepping through your code and seeing why things are not working.
Debugging
Advanced Debugging
So, I READ the FIRST Debugging article. I will probably read the ADVANCED debugging article SOON. Um, I ALSO watched Shaun SPALDING'S TUTORIAL video on YouTube about Debugging in GameMaker 2. So that's brought me a LITTLE more up to speed on how the debugger WORKS.

Then I tried placing a BREAKPOINT in the COLLISION event of the Warp object with the PLAYER object.

obj_player.x = targetX ;
obj_player.y = targetY ;
I put it just before HERE -> room_goto(targetRoom) ;

But NOTHING happened. My character just WALKS off screen still...
 

TheouAegis

Member
You need to assign a Sprite to your warp object. If there is no Sprite assigned to it, there can be no collision event. Just give it a simple square Sprite, then uncheck the visible flag in the object properties.
 

Yal

šŸ§ *penguin noises*
GMC Elder
You can try DEBUGGING this issue by adding a debug MESSAGE in the collision EVENT, if the message is SHOWN it means the event is TRIGGERED, and if it isn't shown, it MEANS the event is not triggered. If it's NOT triggered, that MEANS you should figure out why it isn't HAPPENING (e.g. follow TheouAegis's SUGGESTION to make sure the object has a COLLISION mask), if it's triggered, INSTEAD you should figure out why the code DOESN'T do what YOU want it to do.

Also UNRELATED are you aware that SETTING the player's COORDINATES before changing rooms has NO effect since EACH room has its OWN set of INSTANCES. It will only WORK if the PLAYER is PERSISTENT, otherwise you need to use GLOBAL variables to transfer the VALUES to the next room, and then make the player MOVE in its CREATE EVENT.
 
Top