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

Checking a list of size 400-1000 for random numbers.

N

Nathan Archer

Guest
Hi I need help with a pretty basic problem and how best to approach it.

What I'm trying to do is:

-Have a list of 400-1000 "levels" which are chosen randomly
-Each level done is recorded
-Each level done is not repeated

The way I currently have it set up is adding each index of the level added to a ds_list, and using a while loop to check from the range (random_range(0, 400)), to grab a new one.

The problem is as the problems get closer to the maximum, the loop repeats more and more, to the point where the game crashes or freezes.

What's the best approach to give the player a random number every time that doesn't repeat within a certain range?
 

chamaeleon

Member
Hi I need help with a pretty basic problem and how best to approach it.

What I'm trying to do is:

-Have a list of 400-1000 "levels" which are chosen randomly
-Each level done is recorded
-Each level done is not repeated

The way I currently have it set up is adding each index of the level added to a ds_list, and using a while loop to check from the range (random_range(0, 400)), to grab a new one.

The problem is as the problems get closer to the maximum, the loop repeats more and more, to the point where the game crashes or freezes.

What's the best approach to give the player a random number every time that doesn't repeat within a certain range?
Stuff the range of numbers into a ds_list and ds_list_shuffle() it, then work your way through it from beginning to end? Just increment the offset into the ds_list as you need a new item.
 
N

Nathan Archer

Guest
Stuff the range of numbers into a ds_list and ds_list_shuffle() it, then work your way through it from beginning to end? Just increment the offset into the ds_list as you need a new item.
ds_list_shuffle()

WOW I didn't know that was a thing. That's very helpful, thank you!
 
Top