im not sure if this has been talked about anywhere, but using the arrays in the world editor you cannot make 2d arrays. i dont know if you can using JASS but i know you cant do it the normal way. there was a map i was working on where i needed 2d arrays and then i remembered back in my "advanced c++ programing" class we had to overloard the array index operator [] to work on a class object that held a 2d array in it. we had to convert 1-dimensional arrays into 2d arrays. heres how you can do it:
make an array of size [max_rows * max_columns], if you wanted a 3x10 2d array, for example, make an array of size 30. then when ever you want to access one of the elements in the array just plug in this formula for the index:
[((row-1)*max_columns)+column]
where "row" is the row that you want to access, "max_columns" is the total number of columns you have in the "2d array", and "column" is the column that you want to access.
in this example i'll use 3 rows and 10 columns, each row is for a stat, each column is for a hero:
[hero][ 01 ][ 02 ][ 03 ][ 04 ][ 05 ][ 06 ][ 07 ][ 08 ][ 09 ][ 10 ]
[STR][ 01 ][ 02 ][ 03 ][ 04 ][ 05 ][ 06 ][ 07 ][ 08 ][ 09 ][ 10 ]
[INT][ 11 ][ 12 ][ 13 ][ 14 ][ 15 ][ 16 ][ 17 ][ 18 ][ 19 ][ 20 ]
[AGI][ 21 ][ 22 ][ 23 ][ 24 ][ 25 ][ 26 ][ 27 ][ 28 ][ 29 ][ 30 ]
now if i want to get hero4's AGI you can see that it's index 24 but just so you dont have to look at a table every time you can simply plug in the forumla
((row-1)*max_columns)+column
AGI is row 3
(( 3 -1)*max_columns)+column
max_coumns will always be 10 for this array
(( 3 -1)* 10 )+column
hero4 is column 4
(( 3 -1)* 10 )+ 4
(( 3 -1)* 10 )+ 4 = (2 * 10) + 4 = 20 + 4 = 24
every time you want to get a stat for a hero you just plug in the row and column in the formula and the game will take care of the rest.
before anyone says you can just use actions functions to find a hero's stats, this is different. i used this in my map for stats per level. i set all of them to 0 and every time a hero learned a certain ability they would gain more stats per level, ex:
a hero learns an ability
learned ability equal to evasion
set stats[((3-1)*10)+<playernumber of owner of hero>] equal to stats[((3-1)*10)+<playernumber of owner of hero>] + 1
and
hero gains a level
add stats[((1-1)*10) +<playernumber of owner of hero>] to leveling hero's strength
add stats[((2-1)*10) +<playernumber of owner of hero>] to leveling hero's intelligence
add stats[((3-1)*10) +<playernumber of owner of hero>] to leveling hero's agility
this could be useful to some of you who want to use 2-dimensional arrays.
make an array of size [max_rows * max_columns], if you wanted a 3x10 2d array, for example, make an array of size 30. then when ever you want to access one of the elements in the array just plug in this formula for the index:
[((row-1)*max_columns)+column]
where "row" is the row that you want to access, "max_columns" is the total number of columns you have in the "2d array", and "column" is the column that you want to access.
in this example i'll use 3 rows and 10 columns, each row is for a stat, each column is for a hero:
[hero][ 01 ][ 02 ][ 03 ][ 04 ][ 05 ][ 06 ][ 07 ][ 08 ][ 09 ][ 10 ]
[STR][ 01 ][ 02 ][ 03 ][ 04 ][ 05 ][ 06 ][ 07 ][ 08 ][ 09 ][ 10 ]
[INT][ 11 ][ 12 ][ 13 ][ 14 ][ 15 ][ 16 ][ 17 ][ 18 ][ 19 ][ 20 ]
[AGI][ 21 ][ 22 ][ 23 ][ 24 ][ 25 ][ 26 ][ 27 ][ 28 ][ 29 ][ 30 ]
now if i want to get hero4's AGI you can see that it's index 24 but just so you dont have to look at a table every time you can simply plug in the forumla
((row-1)*max_columns)+column
AGI is row 3
(( 3 -1)*max_columns)+column
max_coumns will always be 10 for this array
(( 3 -1)* 10 )+column
hero4 is column 4
(( 3 -1)* 10 )+ 4
(( 3 -1)* 10 )+ 4 = (2 * 10) + 4 = 20 + 4 = 24
every time you want to get a stat for a hero you just plug in the row and column in the formula and the game will take care of the rest.
before anyone says you can just use actions functions to find a hero's stats, this is different. i used this in my map for stats per level. i set all of them to 0 and every time a hero learned a certain ability they would gain more stats per level, ex:
a hero learns an ability
learned ability equal to evasion
set stats[((3-1)*10)+<playernumber of owner of hero>] equal to stats[((3-1)*10)+<playernumber of owner of hero>] + 1
and
hero gains a level
add stats[((1-1)*10) +<playernumber of owner of hero>] to leveling hero's strength
add stats[((2-1)*10) +<playernumber of owner of hero>] to leveling hero's intelligence
add stats[((3-1)*10) +<playernumber of owner of hero>] to leveling hero's agility
this could be useful to some of you who want to use 2-dimensional arrays.


