GMS 2 Room transitioning doesn't work at all

Discussion in 'Programming' started by steph, Jul 14, 2019 at 10:18 AM.

Tags:
  1. steph

    steph Member

    Joined:
    Sunday
    Posts:
    3
    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!
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,125
    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) {
    
     
  3. steph

    steph Member

    Joined:
    Sunday
    Posts:
    3
    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: Jul 14, 2019 at 11:53 AM
  4. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,125
    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.
     
  5. steph

    steph Member

    Joined:
    Sunday
    Posts:
    3
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice