• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

3D Arrays...

Status
Not open for further replies.
What do you need 3D arrays for? Out of curiosity...

Overall, 3D arrays usually aren't necessary and usually lead to really high indexes, sometimes beyond the limit of 8192. If you really do need to use dynamic arrays, I suggest doing a search for open arrays (unused), similar to this fashion:
http://wc3jass.com/viewtopic.php?t=3443

Otherwise I guess you can look up some sort of formula, but to my findings, none of them work properly, and thus most resort to a manual search.

Besides, the interface is usually nasty in the end. :P
 
Here's one method of doing 3D arrays. May not be the best but it should be easy to follow I hope.
Assuming you want this to work for all possible values for indexes a, b, c (set array[a][c] = x) I would end up using two hashtables. If you can limit the range of values for one of the indexes, you can reduce this to one hashtable easily enough.

This implementation may be slightly off because I'm just typing it off the top of my head:
JASS:
globals
    hashtable Table1 = InitHashTable()
    hashtable Table2 = InitHashTable()
    integer freeIndex = 0
endglobals

function NewIndex takes nothing returns integer
    set freeIndex = freeIndex + 1
    return freeIndex
endfunction

function SetInteger takes integer a, integer b, integer c, integer value returns nothing
 local integer index
    if HaveSavedInteger(Table1, a, b) then
        set index = LoadInteger(Table1, a, b)
    else
        set index = NewIndex()
        call SaveInteger(Table1, a, b, index)
    endif
    call SaveInteger(Table2, index, c, value)
endfunction

// This GetInteger function assumes a value is already stored
// Add error checking if you want
function GetInteger takes integer a, integer b, integer c returns integer
 local integer index = LoadInteger(Table1, a, b)
    return LoadInteger(Table2, index, c)
endfunction
 
I'm just curious myself. There was a tutorial before, but then it disappeared. I read it before so I know how to use them, but I dunno why the tutorial vanished.

I don't use JASS, I use GUI. 3D Arrays, though they can get fairly high, usually don't.
My formula for 3D Arraying is;
((Max number of Array2) x (Array 1)) + Array 2
eg. if you wanted to store 7 different units for 1 player into 3D array, you do:

For Each Integer A from 1 to 7:
Set Unit = Unit[(7 x Player Number) + Integer A]
 
My formula for 3D Arraying is;
((Max number of Array2) x (Array 1)) + Array 2
eg. if you wanted to store 7 different units for 1 player into 3D array, you do:

For Each Integer A from 1 to 7:
Set Unit = Unit[(7 x Player Number) + Integer A]

Since you are using [a] = [a*maxB+b], it is a 2D array. ;)

3D arrays would be [a][c]. As for the tutorial, I don't remember seeing that one. Maybe it is on a different site? Or you can check the graveyard.
 
Status
Not open for further replies.
Back
Top