HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Array of arrays

03-17-2004, 11:46 AM#1
Joakim
Sorry for beeing such a noob, but im not familiar with triggering like conventional languanges.

Anyhow, i want to do a simple thing. In quasi-code it would look like this

TheArray [1][1] = "whatever";

or

TheArray (1,1) = "whatever"

Is it possible to make this? I'm thinking assigning arrays to arrays.

thxs
03-17-2004, 12:00 PM#2
Cubasis
Quote:
Originally Posted by Joakim
Sorry for beeing such a noob, but im not familiar with triggering like conventional languanges.

Anyhow, i want to do a simple thing. In quasi-code it would look like this

TheArray [1][1] = "whatever";

or

TheArray (1,1) = "whatever"

Is it possible to make this? I'm thinking assigning arrays to arrays.

thxs

Nope :/, sorry, JASS (the language) does not support 2+ dimension arrays. Your best bet is emulating it with something like [x+y*maxX] or using gamecache to get your needs.

Cubasis
03-17-2004, 06:48 PM#3
Ligature
So what you want is a "container" one-dimensional array filled with other "content" one-dimensional arrays.

The simplest route (no jass involved) would be to make two ordinary arrays. One contains what you wanted in the "content" arrays. The other contains integers that tell the index in the new array where each of the imaginary "content" arrays end.

For example, if I wanted array member (3, 4) in my imaginary 2-d array, I would refer to array member [IndexArray(3)+4] in the new massive array.

The down side is sizeability: you'll have to manage that yourself, by shifting all the values below the one you add in the array, and changing the indices in the index array appropriately.

Good hunting!
03-18-2004, 01:00 AM#4
AIAndy
Shifting elements in such a potentially huge array is very expensive, so this solution should be avoided. Better use a fixed length of the subarrays. Then the formula Cubasis gave works: x + y * maxX
In that case x,y is the element you want to retrieve and maxX is the maximum size of x.
03-18-2004, 01:55 AM#5
weaaddar
That generally feels awkward.
As most are content in seeing it as an array of arrays with the X being the Container and Y being the subscript of the array of the child array.
Thus: X*Ymax+y is much more reasonable and is exactly how C does its 2d arrays.
03-18-2004, 01:56 AM#6
linkmaster23
You can have an array in an array? New to me...
03-18-2004, 01:58 AM#7
weaaddar
well not in jass but in java its very normal to be able to do such a declaration
int[][] x=new int[10][10]
03-18-2004, 02:01 AM#8
linkmaster23
Ah, no wonder. Silly me. ;)
03-20-2004, 02:58 PM#9
Joakim
Thank you all for your feedback