• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML [SOLVED] Iterating DS_Grid_Create ~ Nesting/Arrays/DS

D

Dan B

Guest
I'm confused as per how to access something like this. When I debug this:

Code:
// Create
for (var i = 0; i < 5; ++i) {
    catagory_grid[i] = ds_grid_create(10,10)
}
In the 'catagory_grid' variable* within the obj_inv, it equals:
catagory_grid[0] = 0
catagory_grid[1] = 1
catagory_grid[2] = 2
~etc

So my question is, where did the 5 grids go?

Assuming that this method does not work fundamentally; is there a better way I can dynamically add ds_grids as more 'Categories' are added to my software? I was hoping to be able to nest my grids within this array, but it only seems to record nominal/meaningless number, rather than the grid I expected... :bash:

Thanks~
 

FrostyCat

Redemption Seeker
All data structures are referenced using numeric ID handles. You are not putting grids into the array, you are putting the IDs of grids into the array. In your case, category_grid[0] holds grid #0, category_grid[1] holds grid #1, and so on. All ds_grid_*() functions will work on these IDs as usual.

There are plans to promote data structures to true data types in the undetermined future, but for now what you saw is expected behaviour.
 
D

Dan B

Guest
Thanks for the reply. The confirmed insight is good to know, I can stop racking my mind about that part!

Unfortunately, I have no idea how to work around this logic as far as iterating more grids based on the amount of "catagories" the user has added..

*EDIT*
I think I understand what you mean, I will do some tests.
 
Last edited by a moderator:

FrostyCat

Redemption Seeker
What's there to work around? Just use those stored grid IDs as-is, ds_grid_*() functions won't care where they came from. Here are two examples:
Code:
ds_grid_set(category_grid[1], 0, 0, "foo");
Code:
for (var i = array_length_1d(category_grid)-1; i >= 0; i--) {
  ds_grid_set(category_grid[i], 0, 0, "bar");
}
 
D

Dan B

Guest
My lack of DS understanding in GML is the issue. Those examples are very helpful.

Thank you.
 
Top