• 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!

Legacy GM How to code a grid system in 3D

H

HenrikoNumberOne

Guest
Hello!

I am trying to make a grid system in GM 3D (similar to Minecraft), but to no success. How would I go about making this? Do the ds_grid functions even work in a three-dimensional space?

Any help would be much appreciated!
 

jo-thijs

Member
Hello!

I am trying to make a grid system in GM 3D (similar to Minecraft), but to no success. How would I go about making this? Do the ds_grid functions even work in a three-dimensional space?

Any help would be much appreciated!
3D grids are not directly supported by GameMaker, but they're easy to make yourself.

You can put arrays or ds_lists inside the cells of ds_grid.

You can have an array of ds_grids.

You can represent an MxNxK grid as an (M*K)xN grid
where the first M rows correspond to the columns of the 3D grid at K=0,
the second M rows correspond to the columns of the 3D grid at K=1,
and so on.
Then just keep track of the dimension M in some other variable.

Whichever way you go, it'd probably be best if you'd create scripts to perform 3D grid creation, access, destruction and so on.
That way, it's easier to be consistent, it's easier to make changes and your code will be more readable.
 

CMAllen

Member
All arrays of any size, no matter how complex, are all 1-dimensional in memory. The 'dimensions' of an array are purely superficial. Once you realize this, you can create a function to treat any array as any size and shape. What matters is having it large enough to encompass the totality of data being stored. A 10x10x10 3-dimensional array needs 1000 entries, for example, so a 1d array of 1000 entries can just as easily be interacted with as though it were that 10x10x10 3d array.
 
Top