Help with store an array into ds list

H

hiep

Guest
I want to create an array that store 10 element with boolean type. But i dont know how to call element 0 when i push it into ds_list

Is it the same location with the array ? Like ds_list[0] == array[0] ?

And when i push list into map. Is it change location too ?

Thanks for advance !
 

NightFrost

Member
To create the list and array and then place the array in first position (note the use of accessor notation)
Code:
my_list = ds_list_create();
my_list[| 0] = array_create(10, 0);
Because GML doesn't yet have accessor chaining you must pull the array out of the list before you can read it:
Code:
var this_array = my_list[| 0];
var first_item = this_array[0];
 

samspade

Member
thanks you
One thing to note - given your other recent posts about lists about saving - is that you can save, using the json structure, lists nested in lists (assuming they are marked as such), but that will not save nested arrays. So you'll lose all the data in the array if you save the list. As long as you aren't doing that, you can move things around pretty freely and access things as NightFrost described.
 
H

hiep

Guest
Thanks you first samspade. Sorry my bad english but. You mean i can save an array into list then save list into map. Then when i need array i can do like NightFrost said.
And i cant save array into map ?
 

samspade

Member
Thanks you first samspade. Sorry my bad english but. You mean i can save an array into list then save list into map. Then when i need array i can do like NightFrost said.
And i cant save array into map ?
You can put arrays in lists, and arrays in maps. Inside of GM you can put any data structure in an array and any array in a data structure and put those inside of other arrays or data structures. What I am saying is that if you attempt to save that data through the json format, i.e. so that you can close GM and then reload it, you will lose the data in the array.
 
Top