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

[SOLVED] What's going on with 2D arrays

Bentley

Member
I just clicked on "array_height_2d" and found the function is deprecated. I then read about arrays and the manual talks about arrays with multiple dimensions and gives example code using [row][col] (or [col][row]) syntax.

In addition, the error highlighting doesn't show up when you code that way, but you get an error message when you run the project.

Is it just that the manual updated a little prematurely?
Also, as this is how arrays will be, can you initialize a multi-dimensional array in one line (like you would with a ds_grid)?

Or does it have to be something like this:
Code:
var a, rows, cols;
a = [];
rows = 5;
cols = 2;
for (var j = 0; j < rows; j++)
{
    for (var i = 0; i < cols; i++)
    {
        a[rows][cols] = something;
    }
}
What if I run the above code but set
Code:
a[3][3] = array_create(3);
Will I access that internal array via:
Code:
var b = a[3][3];
b[0] = something;
b[1] = something;
b[2] = something;
I assume this would be incorrect right?
Code:
a[3][3][0] // Would NOT access first position of array at row 3 col 3
What if your array, "a", has a third dimension. How would GM know whether you're accessing the external arrays third dimension versus accessing the internal array directly at position 0. (Sorry if my terminology is off). Just trying to get a grasp of what's coming.
 
Last edited:

Simon Gust

Member
This isn't exactly a 2D array, this is an "array inside array". You can still do 2D arrays like in GM:S 1.4, that shouldn't have been removed.
Manual entry doesn't say anything about deprecation.
array_height_2d probably doesn't work with your code, as you aren't supplying a 2D array.
 

TailBit

Member
There was another topic about this, they simply updated the manual before pushing out the changes ..
 

Bentley

Member
This isn't exactly a 2D array, this is an "array inside array". You can still do 2D arrays like in GM:S 1.4, that shouldn't have been removed.
Manual entry doesn't say anything about deprecation.
array_height_2d probably doesn't work with your code, as you aren't supplying a 2D array.
Go to the manual. Search for array. Go to 2d array and it says in the name. It also says it on the page
 

Bentley

Member
There was another topic about this, they simply updated the manual before pushing out the changes ..
Ok. I don't keep up with every page so forgive me for asking mr. dot dot dot lol. Just kidding. But its more than just the manual. The syntax is accepted when coding. There is no error highlighting like you would normally get.
 
Top