Know current room name?

V

Vincent

Guest
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?
 
  • Wow
Reactions: Mut
V

Vincent

Guest
@jazzzar So I write

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

Is that correct?
 
V

Vincent

Guest
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
 
J

jackhigh24

Guest
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.
 
J

jackhigh24

Guest
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;
 
J

jackhigh24

Guest
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.
 
V

Vincent

Guest
@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?
 
J

jackhigh24

Guest
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
 
V

Vincent

Guest
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
 

jazzzar

Member
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
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 :)
 
J

jackhigh24

Guest
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
 
Top