• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Choose command based on room name

J

jef

Guest
Dear gamemaker users!

My situation I have made one object and two rooms. One room is called 'outside' and the other is called 'ínside'. I want object to set run=true when its in room 'outside'. And when object is in room 'ínside' it should set run=false.

I used the following line to find out in which room object is.
Code:
roomname = room_get_name(room)
Now I need a line where the object chooses code, based on in which room the object is.
I tried the following and this did not work:
Code:
if (roomname==outside) {run=true}
if (roomname==inside) {run=false}
Please fix the code so it works as I want.
 

jo-thijs

Member
Dear gamemaker users!

My situation I have made one object and two rooms. One room is called 'outside' and the other is called 'ínside'. I want object to set run=true when its in room 'outside'. And when object is in room 'ínside' it should set run=false.

I used the following line to find out in which room object is.
Code:
roomname = room_get_name(room)
Now I need a line where the object chooses code, based on in which room the object is.
I tried the following and this did not work:
Code:
if (roomname==outside) {run=true}
if (roomname==inside) {run=false}
Please fix the code so it works as I want.
Hi and welcome to the GMC!

When you type outside or inside, you're not using strings, but room indices, which are numbers.
However, room_get_name does return a string, not a number.
As a result, your comparisons won't work.

There are a couple of fixes.
The best one being this:
Code:
if (room==outside) {run=true}
if (room==inside) {run=false}
A slightly worse one being this:
Code:
roomname = room_get_name(room);
if (roomname=="outside") {run=true}
if (roomname=="inside") {run=false}
 
  • Like
Reactions: jef
Top