HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Multidimensional Item Arrays

02-19-2004, 09:17 PM#1
LegolasArcher
For a map Im working on I need multidimensional item arrays, but the game cache doesnt support item storage. I may wind up using dummy units with inventories, but Id rather not. Is this possible, JASS or not.
02-19-2004, 09:42 PM#2
Shimrra
I don't believe there is.
02-19-2004, 09:54 PM#3
Cubasis
Erhm

If you are open to using OO (gamecache), then this is indeed possible.

To store any "handle" type (widgets are handle types (items are widgets)), you just convert the handle into a integer.... and then store the integer in the game-cache... That way you can get it later...convert the integer into a Item variable...and there you are.

Anyways, other than using game-caches, your only options are unit-inventories or just emulated 2d arrays.

Cubasis
02-19-2004, 10:08 PM#4
Vexorian
for some reason Cubasis didn't mention the way to convert an item to an integer:

Code:
function Handle2I takes handle h returns integer
    return h
    return 0
endfunction

function I2Item takes integer i returns item
    return i
    return null
endfunction

First function will convert anything to an integer, second will convert an integer to an item (only if that integer was an item)

Althought you may like to try a fake array instead of game cache, game cache is a little slower than other stuff, unless you want to be able to save it for the next maps.

To fake a multidemensional array from a normal array you will need an operation that converts the n index into a number from 0 to 8191
02-20-2004, 03:41 AM#5
Narwanza
Sry vex, I might be able to help, but I just don't understand what you mean by a multidemsional item array, could you expound more?
02-20-2004, 05:32 AM#6
Hunter0000
an array with two index's, like instead of
<I>(index) it could be
<I>(index)(index)
02-20-2004, 05:45 AM#7
Narwanza
ohhhhhhhh....... i c now. hmmmmm.... that is a brain twister. I will ponder on it. Can you tell us your purpose for this Lord Vexorian? I might be able to find a reasonable workaround (not saying you can't) for this situation. I dunno.
02-20-2004, 05:50 AM#8
BonsaiSan
Hello (EDIT: Bonsai no lead question plopelly... so Bonsai no give lelevant answel to youl question...),

Say you want to keep tlack of the numbel of kills a playel makes pel level. Thele ale 40 levels and 10 playels.

In 1 dimensional way you would do this like this:

PLAY_01[level#](#kills)
...
PLAY_10[level#](#kills)

So you need 10 single allay valiables...

In 2 dimensional way you do like this:

KillPelLevel[level# + (play# * 41)](#kills)

So you tuln single allay# into folmula.

Tlust Bonsai, is vely simple to do. You simply have to lefel to 2dimensional allay like folmula.

Hope this helps you :)
02-20-2004, 11:53 AM#9
Cubasis
Lol,

*knocks a head 5 times into wall*

Yes, these *points at vex's post* are the functions you need to convert a item to a integer :P

Anyways, both me and Vex explained (and fully knew how to, most likely) that you need to emulate/simulate a 2d array by using a simple algorithm on the two Index values to get a element-number.

However, we obviously didn't explain how to do it *knocks head another 10 times into wall*. But that didn't mean Vex didn't know how to solve the problem :D

Anyways, BonsaiSan explained how to do it properly enough. I actually prefer to use a simple function to get me the correct index, so i don't have to write the algorithm every time, as that could result in a hard-to-find logic bug at some point.
Then i would just do: KillPelLevel[ 2dI( level#, play#, 41 ) ]
The last parameter (41) would tell the function how many elements there are for each player in my array.

However, using gamecache to do this same thing is completely ok, it just depends on what you're doing. F.ex., if you're going through this whole 2d array, comparing stuff, or anything like that, all the time. Then you should try to go for emulated 2d arrays instead.
However, if you're just storing this for later access, or just something simple like this, then gamecache is a completely fine way to go. The performance difference is unnoticable, as this is just a normal access call. It does not lag anything in-game...this is true with almost all actions, becouse this thread just runs completely in the background, and can be doing whatever it wants. There are just a set of function that actually can make the player's computer slow down, these normally involve in something visual.

Anyways

Cubasis
02-20-2004, 01:40 PM#10
Vexorian
Cubasis. be careful that wall is public property...

Just to avoid making this post a spammy post, weaaddar always use fake 2d arrays, he has a function that is like

Code:
function Ix takes integer x, integer y returns integer
    return x*a+y
endfunction

Replace a ith the maximum number of y indexes

then to use than would be ItemArray[Ix(2,3)] that would get the value with x index 2 and y index 3.

Although that was just a 2d array, a 3d array would be like

Code:
function xyz takes integer x, integer y, integer z returns integer
    return x*(a*b)+y*a+z
endfunction

replace a with the maximum number of z indexes and b with the maximum number of y indexes.

A 4D array would be like x*(a*b*c)+y*(a*b)+z*c+p

A 5d array would be... well it would be something like the last thing....

Although remember that the maximum array size is 8192
02-20-2004, 10:24 PM#11
Vexorian
p is what I usually use when I don't know what to use (x, y , z, (p?))
02-20-2004, 10:30 PM#12
Vexorian
t, good idea, I wonder what to use for the fith dimension.

I was thinking on using

x,y,z, p,q,r,s,t,...