Know current room name?

Discussion in 'Programming' started by Vincent, Aug 2, 2016.

  1. Vincent

    Vincent Member

    Joined:
    Aug 2, 2016
    Posts:
    59
    I have an object in my platformer that teleports you to other room. Is there a way to recognise the current room so depending on the current room that object brings you to one room or another?
    For example: If you're in room 1, it takes you to room 5. If you're in room 3, it takes you to room 4. Is it possible to do that using a single object? Is there any other way?
     
  2. Nux

    Nux Member

    Joined:
    Jul 7, 2016
    Posts:
    371
    Alan Chan likes this.
  3. jazzzar

    jazzzar Member

    Joined:
    Jun 29, 2016
    Posts:
    514
    you can use the read-only variable which is room
    so you can check like that :
    Code:
    if room==level1
    {
           //do something
    }
     
    Gast, Alan Chan and OnLashoc like this.
  4. Vincent

    Vincent Member

    Joined:
    Aug 2, 2016
    Posts:
    59
    @jazzzar So I write

    if (place_meeting (x+1, y, obj_barrier))
    and (room == rm_1)
    {
    room_goto (rm_2)
    }

    Is that correct?
     
  5. jazzzar

    jazzzar Member

    Joined:
    Jun 29, 2016
    Posts:
    514
    the x and y parameters depends on your case, well the whole thing depends on what you want to do, try it, if it works than that's good :)
     
  6. Vincent

    Vincent Member

    Joined:
    Aug 2, 2016
    Posts:
    59
    When you come to room 1 after visiting room 2, I want to destroy the instace in the start of the room 1 and make another one appear in the place you go to room 2. How do I do that? @jazzzar
     
  7. jazzzar

    jazzzar Member

    Joined:
    Jun 29, 2016
    Posts:
    514
    I actually didn't understand that?
     
  8. jackhigh24

    jackhigh24 Member

    Joined:
    Jun 21, 2016
    Posts:
    604
    i think he means how to have his player start in the same posistion in the next room as he is in the other room, so just save the x and y of your player in the second room to a global.yourvarX and global.yourvarY and also save what room your in just as your leaving it in a global.yourvarRoom, then when in new room check if that global.yourvarRoom then if it was room2 use those global X and Y vars to set the new posistion of the player.
     
    jazzzar likes this.
  9. Vincent

    Vincent Member

    Joined:
    Aug 2, 2016
    Posts:
    59
    Last edited: Aug 3, 2016
  10. jackhigh24

    jackhigh24 Member

    Joined:
    Jun 21, 2016
    Posts:
    604
    ok so the way you are putting that then you want the player to be created in room 2 at the same place he was at in room 1, is that right, if so its still the same setup as i put in my post, you will have to have a global.playerX and a global.playerY to save where he was as you leave room one, example

    create event object player
    Code:
    x = global.playerX;
    y = global.playerY;
    
    step event object player
    Code:
    if (place_meeting (x, y+1, obj_barrier)) and (room == rm_1)
    {
    global.playerX = x;
    global.playerY = y;
    room_goto (rm_2);
    }
    
    before using these right at the start on your game you will have to set those globals to something, so in your menu room before you go to any level set them up to where you want the player to start at in room 1 so say he is starting at x = 100 and y = 100 then set those globals to that

    Code:
    global.playerX = 100;
    global.playerY = 100;
    
     
  11. Vincent

    Vincent Member

    Joined:
    Aug 2, 2016
    Posts:
    59
  12. jackhigh24

    jackhigh24 Member

    Joined:
    Jun 21, 2016
    Posts:
    604
    no problem, just need to read that manual a little more and you will soon be able to do this type of things easy, i can see it english holding you back there, but still keep at and you will be good.
     
  13. Vincent

    Vincent Member

    Joined:
    Aug 2, 2016
    Posts:
    59
    @jackhigh24 and right when a room starts do I put global.playerX and global.playerY to the place I want them to start in the new room, right?
     
  14. jackhigh24

    jackhigh24 Member

    Joined:
    Jun 21, 2016
    Posts:
    604
    if you want you can do that, will depend on where you need it in that room, if your just going to be starting in the new room in the same place as the last room then just leave it as it is as that in the create event will set it to the same posistion it was in last room so long as when you change rooms you have it set they way i showed you there
     
  15. Vincent

    Vincent Member

    Joined:
    Aug 2, 2016
    Posts:
    59
    So
    x = global.playerX;
    y = global.playerY;
    goes in the player create event
    global.playerX = 100;
    global.playerY = 100;
    when room changes
    if (place_meeting (x, y+1, obj_barrier)) and (room == rm_1)
    {
    global.playerX = x;
    global.playerY = y;
    room_goto (rm_2);
    }
    in player step event, right? @jackhigh24
     
  16. jazzzar

    jazzzar Member

    Joined:
    Jun 29, 2016
    Posts:
    514
    Hey vincent, you seem pretty new to game maker and gml, and you seem lost in how everything works, i recommend watching some tutorials on youtube and/or download the tutorials that comes with game maker, read up the manual, play with gm a little here and here before you actually try to make a game, it's bad when someone writes the whole code for you, you will end up learning nothing, please do not be offended by that, that is just for help and nothing else, i hope the best of luck for you :)
     
  17. Vincent

    Vincent Member

    Joined:
    Aug 2, 2016
    Posts:
    59
    jazzzar likes this.
  18. jackhigh24

    jackhigh24 Member

    Joined:
    Jun 21, 2016
    Posts:
    604
    ok so you got that a little mixed up, like @jazzzar says you need to do some good practice, but i will repost the code and put comments in so you can understand it a bit better

    so first up you need this in a room before you goto your first game room, so you would have a empty room and make an object call it oInitial and place it in that empty room, this should be the very first room in the resource tree, as that is where game maker will start from, in that oInitial create event do this

    oInitial create event
    Code:
    global.playerX = 100;// this will give the player it first starting x location when you create the player in the first game room
    global.playerY = 100;// this will give the player it first starting y location when you create the player in the first game room
    room_goto_next();// this will just send your game to the next room in the resource tree
    
    object player create event
    Code:
    x = global.playerX;// this will make the player start at that x location we set just before
    y = global.playerY;// this will make the player start at that y location we set just before
    
    step event object player
    Code:
    if (place_meeting (x, y+1, obj_barrier)) and (room == rm_1)
    {
    global.playerX = x;// this will save its x location just before you jump rooms, so that each time you create the player again that code in the create event will read this
    global.playerY = y;// this will save its y location just before you jump rooms, so that each time you create the player again that code in the create event will read this
    room_goto (rm_2);// if your going to be going back and forth from rooms then you will have to have lots of if this room is room what ever then goto room what ever
    }
    
    so you will never have to change the x and y locations as it will always update it when your jumping rooms
     
    jazzzar likes this.

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