GameMaker Room transitioning doesn't work at all

S

steph

Guest
Hi, I'm completely new to programming and decided to follow FriendlyCosmonaut's Farming RPG tutorial series on youtube. I'm trying to set up the room transition area but my character just walks right through it with no reaction.

This is the code I put under the player's Step action for the collision and transition:

Code:
//------ collision

// horizotal
if(moveX != 0){
if(place_meeting(x+moveX, y, obj_collision)){
    repeat(abs(moveX)){
    if(!place_meeting(x+sign(moveX), y, obj_collision)){
        x += sign(moveX);
        } else {break;}
}
moveX = 0
}
}

// vertical
if(moveY !=0){
if(place_meeting(x, y+moveY, obj_collision)){
        repeat(abs(moveY)){
    if(!place_meeting(x, y+sign(moveY), obj_collision)){ y += sign(moveY); }
        else {break;}
}
moveY = 0
}
}

// transition
var inst = instance_place(x,y,obj_transition);
if(inst = !noone) {
   
room_goto(inst.targetRoom);
   
}

//------- apply movement
x += moveX;
y += moveY;

I made obj_transition and under the Create action put this:

Code:
targetRoom = -1;
And at the door where I put up the transition area to enter the building (room2), under Creation Code I put this:

Code:
targetRoom = rm_farm_house;

Any help appreciated!
 

Simon Gust

Member
Does obj_transition have a collision mask or assigned sprite?
Without it, there will be no collision.

Also, slight typo.
This
Code:
if(inst = !noone) {
should be this
Code:
if(inst != noone) {
 
S

steph

Guest
Does obj_transition have a collision mask or assigned sprite?
Without it, there will be no collision.

Also, slight typo.
This
Code:
if(inst = !noone) {
should be this
Code:
if(inst != noone) {
I assigned it to my already-existing collision sprite, which I don't think has any problems. But anyway your typo correction triggered the transition! But the next problem is it wont move the player character to room2 (rm_farm_house), and just resets the player character to the starting position in the current room (aka resets the game)
 
Last edited by a moderator:

Simon Gust

Member
Are you sure the room is reset, it might still switch the room but you aren't noticing.
Or maybe you have another transition object in the second room where you spawn and it sends you back immedeatly.

Is your player object persistent? That might help.
 
S

steph

Guest
I assigned it to my already-existing collision sprite, which I don't think has any problems. But anyway your typo correction triggered the transition! But the next problem is it wont move the player character to room2, and just resets the player character to the starting position in the current room (aka resets the game)
Are you sure the room is reset, it might still switch the room but you aren't noticing.
Or maybe you have another transition object in the second room where you spawn and it sends you back immedeatly.

Is your player object persistent? That might help.
Ahh genius! So yes, it turned that the code was fine and it was indeed correctly transitioning to room2, but I had accidentally placed the player instance in room2 right where the transitioning area is so it would immediately reset my character back to the original room the moment I went through the door. Thanks! would have never realised that with my newbie perspective lol.
 
Top