• 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!

GML Sorting Rooms into a List

Wendell

Member
Guys, I'm in the need of some light for two things:

1.
Lets assume that I have 20 rooms in my game, numbered from 1 to 20.

Whenever you enter a new room, the next one will be one of the other 19, chosen at random.

How can I make to, after entering a new room, the one I was previously would not be repeated when I go to the next? This way I can randomly visit all 20 rooms without repeating none.

I believe that this can be done with an Array, to store all rooms and then removing them as need but I cannot find a way for this to work properly.

2.
Now let's suppose that I have 30 rooms but I want only 20 to be chosen at random to form that previous 20 room list. No idea on how to do this as well, as all my attempts failed miserably.

Any ideas?
 

TailBit

Member
1
- make one object persistent so it doesn't get deleted between rooms that holds the list .. or have a global variable with a list of the rooms
- make the ds_list
- fill it with all the rooms
- use ds_list_shuffle .. note that you might want to call randomize() at the start of your game for it to be random
- then just read from the top and delete the row as you go to that room
2
- if you have a ds_list with X number of rooms .. shuffle it and go through the 20 first using a for loop, that you copy over to your rooms_to_play ds_list ..
 
1. Look into using a ds_list instead. Similar to an array but has useful helper for functions for stuff like removing a room from the list once the player has been a there.

2. Add 30 rooms to the ds_list. run ds_list_shuffle() function on the list to randomise the order. Remove the first 10 rooms from the list. Bingo, you have a list of 20 rooms in random order.

As the player visits each room, just remove the the first room from the list. Once the list is empty, the player has visited all the rooms.

Use ds_list_delete(list_name, 0) to remove first item in list.
 
Top