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