Issue when using ds_list instead of array. [SOLVED]

I just recently, like ten minutes ago, reconfigured some code to use a ds_list instead of an array that I've been using. But it seems that when I want to access it it randomly crashes.

So, falling blocks puzzle game. I've been storing all of the blocks (game objects) in an array and then generating them randomly. Now I've been creating some "special" blocks that behave differently. So to make it easier and more dynamic i switched to using a ds_list, but it doesn't behave the same way.

I used to do:

Code:
instance_create_depth(225,125,100,global.cubeArr[irandom(global.arr_size)]);
global.arr_size is, well, the size of the array.
global.cubeArr is the array where all the different blocks are stored.

I now switched it to:

Code:
instance_create_depth(225,125,100,global.cubes[|irandom(global.arr_size)]);
global.cubes is a ds_list that stores all the different blocks.

Cubes are spawned 10 at the time in a line. What seems to be randomly I get this error:
FATAL ERROR
"instance_create_depth argument 4 incorrect type (undefined) expecting a Number (YYGI32)
at gml_Script_spawn_cubes (line 43) - instance_create_depth(425,125,100,global.cubes[|irandom(global.arr_size)]);"

I can't replicate it, it appears randomly, and not always on the same line, but always on one of the ten lines that look just like the one above but with different x-coords.

I literally have no idea what to do. The code has been working fine with the array code but now this happens with the ds_list version. Can you peeps se anything that I can't maybe?

Please help!
 

NightFrost

Member
Are you changing the size of the DS list after reading its length to global? While you cannot make an array shorter, as there's no command for that, you most certainly can shorten a DS list by removing entries. Also, is the length calculated correctly? If a list has four entries, their positions are zero to three, so your list length global should be list size - 1.
 

FrostyCat

Redemption Seeker
Be it an array or a list, if it is of size n, then its index numbers run 0 through n-1, not 0 through n. You should have done irandom(global.arr_size-1), not irandom(global.arr_size). It's either a matter of beginner's luck or inadequate testing for the problem not to have surfaced when you did the same with arrays.
 
Top