1

Hi guys!
Please give examples of the initialization of multidimensional arrays.
int[][] MMArray;
How do I specify the size of an array?
How to work with dynamic arrays with insert_at, insert_last, etc?
Thanks in advance!

Thumbs up

2

With multidimentional arrays, you can't really initialize their sizes with constructors. However, remember that a 2 dimensional array is just an array of arrays. So mmArray.resize(10) resizes the outer array / the first index. You would need to resize each inner array individually, for example, with a for loop.

for (uint i=0; i<mmArray.length(); i++) mmArray[i].resize(10); 

Insertion and removal work using the same concept. If you want to insert something at [1][2], you would say mmArray[1].insert_at(2, value);

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

3

mmArray[i].resize(10);

this one-dimensional array, I'm interested in for example a two-dimensional array

Thumbs up

4

Consider this:
int[][] map = get_map();
int[] row = map[0];
map[1] = row;
if (map[0][0] != map[1][0]) {
    alert("fatal error", "BGT is broken!");
}
Since a 2 dimensional array is a 1 dimensional array whose type is int[], you can pass around rows from the 2 dimensional array as though they are 1 dimensional arrays. this is because they are.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up