GMS 2 [SOLVED] Can I set the size of a ds_list without a for loop?

P

PepticPaladin

Guest
I want to make a ds_list that is n values long. Can I do this in GML without using a for loop?
 

samspade

Member
I want to make a ds_list that is n values long. Can I do this in GML without using a for loop?
I'm not sure if there's a function for it (I looked in the manual and didn't see one but I might have missed it) however, in GMS 2 at least a simple test shows that they work like arrays - automatically resized to the largest point without erasing lowing numbers - put a break point on the first line of this code and step through it in the debugger:

Code:
test = ds_list_create();
test[| 10] = "Hello";
test[| 5] = "World";
test[| 15] = "!";
ds_list_destroy(test);
test will be undefined, then be a list with 11 spaces, where the 11th space is "Hello" then the sixth space will be "World" and then the list will be resized to 16 spaces and the 16th space will be "!" without changing any of the earlier positions. Further it seems that these added spaces are initialized to 0 by default. I tested this on PC. Not sure if it would be consistent across platform.
 
Top