SOLVED Initialize 2D array


Hi, so I am what I am trying to do is create a 2D array to keep track of collectibles. I have one collectible per level and my game is divided into 6 "worlds", with four levels each. I thought the best way to keep track of which collectibles were collected would be to create a 2D array with the world as the first coordinate and the level as the second, then set it to true or false depending on if it was collected. Where I ran into issues was trying to create this array with a controller object. It's fairly large, and if I'm understanding 2D arrays correctly, you can create them with something like:
my_array[0, 0] = false;
my_array[0, 1] = true;
my_array[1, 0] = false;
my_array[1, 1] = false;
However, with such a large array I though there must be a faster way to do this. Or is it simply that once you define one entry for the array you can add as many as you want without previously defining them? Sorry if this is long, I wanted to give as much context as possible :)


for (var world = 0; world < 6; world ++){

   for (var level = 0; level < 4; level ++){

      my_array[level][world] = false;


You can use a double for loop like this to set all the entries to the array to false initially (and set them to true manually afterwards).

If you want to save this data between games, maybe a ds_grid is better (for 2 reasons).

1) You can just make a spreadsheet, and fill the entries with 0's or 1's, convert it into a csv, and use load_csv to converth that spreadsheet into a usable ds_grid ( I don't know if you want to set any entries to true by default)
2) You can use ds_grid_write/read to save this grid to a file to use between sessions.
Last edited: