HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Simulating a 2d array

02-26-2004, 04:30 AM#1
Narwanza
I know this has been asked before, but I can't seem to find any good threads. How would I simulate a 2d array? Say I wanted a boolean array that was like this isQuestInProgress[(playerIndex),(quest#)]. How would i go about simulating this?
02-26-2004, 06:31 AM#2
Balthamos
I suppose you could make it a number, which is divided into two parts, first two digits represent a two digit number and the two digits after it represent a second, seperate two digit number?

Like this...1409
where, x = 14 and y = 9, or 09

Does that help? It's not difficult to grab substrings of numbers, or to compose numbers with zeros half way in them. Otherwise I don't see many other options I'm afraid.
02-26-2004, 09:12 AM#3
Cubasis
Here Narwanza:

http://kattana.users.whitehat.dk/vie...833554b16e0038

Usage: You have to have a pre-defined limit on one of the indexes. F.ex. if one of the index is the player, then you would have the limit = 12 (or 16).

So you'd call it like this:

set isQuestInProgress[ Ix( 6, 0, 12 ) ]
if ( isQuestInProgress[ Ix( quest#, PlayerIndex, 12 ) ] ) then
DIE!!!
endif

Just remember that for each array, you have to always use the same Limit.

Cubasis
02-26-2004, 09:20 PM#4
Narwanza
Thanks cubasis, i really think the name of that needs to be changed so something other than Ix, because I saw that function and didn't even look at it becuase why would Ix help me?
02-26-2004, 09:44 PM#5
weaaddar
Also if you don't mind a small hit to performance you can use game cache.
Code:
local gamecache myarray=InitGamecache("Whateva.w3v")
call StoreBoolean(myarray,"x","y",true/false)
works dandy.
then when your done just go flush cache.

Anyway its my function and I find that having a really long name would be rather stupid for such a simple func.
02-26-2004, 10:32 PM#6
Narwanza
Well, personally I find having names that do not show any resemblence to the function inside is just stupid. I realize why you called it Ix, but only after I was directed to actually look at that function. I am not going to check out every nameless function in the vault every time I want to find a funciton.
02-27-2004, 12:09 AM#7
Cubasis
Yeah

Nameless functions are horrible in places like Jass Vault.

However, the reason that function is so short, is becouse ... it needs to be used Often, and if one is "emulating" 2d-arrays, one wants to spend as few characters as possible to the "emulation" part of it.

So

set udg_GooGoo[Ix( udg_PineApple[Ix(3,5,12)], 1, 12] = 5

is much better than

set udg_GooGoo[Get2DArrayIndex( udg_PineApple[Get2DArrayIndex(3,5,12)], 1, 12] = 5


So, perhaps it should be submitted to Jass Vault as sumtin like "Get2DArrayIndex", it's comment should "reccomend" people to rename it for their personal use.

Cubasis