How do I get a vaaribal to select a ranodm value 1-3 and make it go to a corrsponding room in GML?

T

tinyunknown

Guest
So, I am trying to make a game where if you touch a door, it will take you to a random room by when touching a door it will pick a random value for a variable room_select(the value is between 1 and 3) and will send the player to the corresponding room number. Can someone help me?
 

Rob

Member
GML:
//create event
rooms[1] = room_1;
rooms[2] = room_2;
rooms[3] = room_3;

//step
var random_room = irandom_range(1, 3);

room_goto(rooms[random_room] );
 
T

tinyunknown

Guest
GML:
//create event
rooms[1] = room_1;
rooms[2] = room_2;
rooms[3] = room_3;

//step
var random_room = irandom_range(1, 3);

room_goto(rooms[random_room] );
Thank you so much!
 

chamaeleon

Member
Although I would go with @Rob's approach in the general case (I like having the option of working with data instead of hard coding things), you do also have the option to use choose().
GML:
room_goto(choose(room1, room2, room3));
The return value of choose can of course be stored in a variable if the jump to another room needs to wait.
 
Top