HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Multi dimensional arrays

03-03-2005, 10:26 PM#1
Zoxc
How can I use multi dimensional arrays in WE? I've tryed to changer the number value in the variables but nothings happen?
03-03-2005, 11:20 PM#2
Bibendus
just use a 1 dimensional array with size = x*y

each cell has his number. Take this example with a 5x5 matrix.

Code:
[01] [02] [03] [04] [05]
[06] [07] [08] [09] [10]
[11] [12] [13] [14] [15]
[16] [17] [18] [19] [20]
[21] [22] [23] [24] [25]
 

Create a single array of size 25 and move on it by X for columns and by (Y-1)*5.
Size of Matrix = Size_X*Size_Y
Move to X = X
Move to Y = (Y-1) * Size_X


Ex. 1
You want to find the item in column 4 row 3
Code:
[01] [02] [03] [04] [05]
[06] [07] [08] [09] [10]
[11] [12] [13] [color=red][14][/color] [15]
[16] [17] [18] [19] [20]
[21] [22] [23] [24] [25]
Value = Array[4 + ((3-1)*5)] = Array [ 4 + 10 ] = Array[14]



Ex. 2
You want to find the item in column 1 row 5
Code:
[01] [02] [03] [04] [05]
[06] [07] [08] [09] [10]
[11] [12] [13] [14] [15]
[16] [17] [18] [19] [20]
[color=red][21][/color] [22] [23] [24] [25]
Value = Array[1 + ((5-1)*5)] = Array [ 1 + 20 ] = Array[21]



Ex. 3
You want to find the item in column 5 row 1
Code:
[01] [02] [03] [04] [color=red][05][/color]
[06] [07] [08] [09] [10]
[11] [12] [13] [14] [15]
[16] [17] [18] [19] [20]
[21] [22] [23] [24] [25]
Value = Array[5 + ((1-1)*5)] = Array [ 5 + 0 ] = Array[5]
03-04-2005, 12:06 AM#3
Koga73
or... an ezer way... if ur wanting 2 make like a boolean for all ur players or something so that each player has like 15 slots all in 1 variable, use:

Code:
variable[((player number of player u want) * 100) + slot number]

that way, slot 507 would b player 5s slot number 7, very simple and effective.
03-04-2005, 04:43 AM#4
Raptor--
Quote:
Originally Posted by Koga73
or... an ezer way... if ur wanting 2 make like a boolean for all ur players or something so that each player has like 15 slots all in 1 variable, use:

Code:
variable[((player number of player u want) * 100) + slot number]

that way, slot 507 would b player 5s slot number 7, very simple and effective.

you do realize you just repeated what the first guy said, basically that theres no native ways to represent matricies -- only to simulate them with functions and an array

+ thats a little inefficient use of memory since its gonna reserve a lot of space that won't be used at all, why not
Value = (player number) * 15 + index
03-05-2005, 12:01 AM#5
Tabris
Quote:
Originally Posted by Raptor--
you do realize you just repeated what the first guy said, basically that theres no native ways to represent matricies -- only to simulate them with functions and an array

+ thats a little inefficient use of memory since its gonna reserve a lot of space that won't be used at all, why not
Value = (player number) * 15 + index

About his spam, I think he doesn't read the post because it was too long for him ^_^

he is wrong about the 100, he didn't read or didn't understand ^_^
this is [x*Sy+y]
where Sy is the size of the y dimension
So 100 is supposed to be the Sy
(and of course : 0<=x<Sx and 0<=y<Sy)

By the way this thread has the best explanantion.
There is already about 3 thread about this subjects ^_^
With this methode you can have array with X dimension because
you can do 2D -> 1D
So 3D=2D+1D->1D+1D=2D->1D
and so on...
Will be in the JASS FAQ
03-06-2005, 04:24 AM#6
Zoxc
so what is the number field in varibles then?