• 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 Check for a room equal to a variable

Hello GameMaker community!
I don't think that this is possible at all but maybe you guys can figure out a way to do it. I was wondering if it was possible to declare a variable with the names of multiple rooms and check if the room equals to that variable like this for example:
Code:
//Create
r = room1, room2, room3

//Step
if(room = r) {
//do something
} else {
//do something else
}
I know that exactly doesn't work but is it possible to do anything like it? If so, let me know, thanks! :)
 
F

Facet

Guest
this is possible with room as number. Probably with room get name too, but numbers better in most situations.
Code:
if room=1 str = 'this is room 1'
if you want names:
Code:
var room_name = room_get_name(room);
you can use else and switch of course too, like a:
Code:
switch(room)
{
do something
}
on create event you can't declare like this if any. Your r is array, so it should be:
Code:
r[0] = room1;
r[1] = room2;
r[3] = room3;
etc

this is theory
 
Last edited by a moderator:

FrostyCat

Redemption Seeker
Stop thinking in terms of checking against magical "multi-values". Think in terms of checking against a set of values iteratively. This means looping.

Create:
Code:
r[0] = room1;
r[1] = room2;
r[2] = room3;
Step:
Code:
var rsiz, found;
rsiz = array_length_1d(r);
found = false;
for (var i = 0; !found && i < rsiz; i++) {
  found = room == r[i];
}
if (found) {
  // In given set of rooms
}
else {
  // Not in given set of rooms
}
My advice for novices learning a new programming language: Don't mope over imaginary syntax and how the language won't support it. Think in terms of existing syntax and how it can be applied.
 
Stop thinking in terms of checking against magical "multi-values". Think in terms of checking against a set of values iteratively. This means looping.

Create:
Code:
r[0] = room1;
r[1] = room2;
r[2] = room3;
Step:
Code:
var rsiz, found;
rsiz = array_length_1d(r);
found = false;
for (var i = 0; !found && i < rsiz; i++) {
  found = room == r[i];
}
if (found) {
  // In given set of rooms
}
else {
  // Not in given set of rooms
}
My advice for novices learning a new programming language: Don't mope over imaginary syntax and how the language won't support it. Think in terms of existing syntax and how it can be applied.
Okay this works perfectly thanks for the help!:)
 
Top