SOLVED Random room entry

F

FoxandRavenGames

Guest
Hi everyone this is my first time posting in here. Just recently started using GMS2 and am working on a 2d side scroller. I'm almost done with a demo for the first level of my game. I have a transition object to go into the next room at the end of each area. Right now I have it set as:
target room = roomx
X = (x start pos)
Y = (y start posting)

So for my target room I want it to random select from a group of rooms I have made so the demo has some repeatability. First level is 4 rooms and I've designed 25 "rooms" for each room and want them to pick randomly so it isn't the same play through each time.

Appreciate the help!
 

chamaeleon

Member
Hi everyone this is my first time posting in here. Just recently started using GMS2 and am working on a 2d side scroller. I'm almost done with a demo for the first level of my game. I have a transition object to go into the next room at the end of each area. Right now I have it set as:
target room = roomx
X = (x start pos)
Y = (y start posting)

So for my target room I want it to random select from a group of rooms I have made so the demo has some repeatability. First level is 4 rooms and I've designed 25 "rooms" for each room and want them to pick randomly so it isn't the same play through each time.

Appreciate the help!
It's not entirely clear if "rooms" means actual GMS rooms or not, but assuming it does.. You have a number of options. You could explicitly do it using choose()
GML:
target_room = choose(room1, room2, ..., room25);
If the rooms are in direct order in the resource tree without any other types of rooms in-between
GML:
target_room = start_room + irandom(end_room - start_room);
You could create an array or data structure you can remove rooms from in order to have a reduced set to pick from as the game progresses, etc.
GML:
rooms = ds_list_create();
ds_list_add(rooms, room1, room2, ..., room25);
...
var choice = irandom(24);
target_room = rooms[| choice];
ds_list_delete(rooms, choice);
or
GML:
rooms = ds_list_create();
ds_list_add(rooms, room1, room2, ..., room25);
ds_list_shuffle(rooms);
...
target_room = rooms[| 0];
ds_list_delete(rooms, 0);
 

Nidoking

Member
I use a persistent sequencer object and create a list of room numbers, which I then have to clear and regenerate when the game restarts. It's handy because it lets me customize how the rooms will be laid out and also lets me look ahead a bit to see what rooms are coming up so I can draw a minimap.
 
F

FoxandRavenGames

Guest
@chamaeleon nice thank you that's very useful I will try it a couple of those ways depending on how I continue production, appreciate your advice.
 
F

FoxandRavenGames

Guest
@Nidoking that's a good idea. I thought about Incorporating a minimal at first but the direction of my game changed. Have another game I was working on prior to this one like a year ago that I definitely want a map for with similar structure, just not a side scrolled so I will take that into consideration for that
 
Top