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!
Pages 1
You are not logged in. Please login or register.
AudioGames.net Forum → Developers room → multidimensional arrays in BGT
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!
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);
mmArray[i].resize(10);
this one-dimensional array, I'm interested in for example a two-dimensional array
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.
AudioGames.net Forum → Developers room → multidimensional arrays in BGT
Generated in 0.042 seconds (19% PHP - 81% DB) with 12 queries