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

for loop to set up ds list

S

stephen2017

Guest
Hi all,
Wondering why the below code isn't working. If I do a manual add to the ds_list in one it works but for some reason not in a for loop as the reference comes back undefined. Can someone please give me some guidance.

Basically I am trying to add numbers from 1 to whatever global.questions is set at then shuffle the list so I can have a random list of numbers.

global.j = ds_list_create();
for (i = 1; i=global.questions; i++){
ds_list_add(global.j,i);
}
ds_list_shuffle(global.j);
 
A

Aura

Guest
Because the loop doesn't run? You're using i = global.questions as the condition for running the loop. That is never true and the loop terminates on its first iteration. Use i <= global.questions instead. That means the code would keep running and numbers being added until i is larger than global.questions, that is, all the numbers have been added.
 
Top