HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Array Question

01-28-2008, 02:31 PM#1
chobibo
Is it possible to make 2D arrays in jass? Thanks
01-28-2008, 02:51 PM#2
MaD[Lion]
with struct u can. or u can reduce array limit for tat.

Learn vJass to know how to use struct.

For the 2nd method example: array[ 10 10 ] this is 2 dimension, with maximum of 99 elements (in theory) in each dimension.
But max array limit in wc3 is 8190 so u can only have 81 elements in first dimension and 90 in 2nd.
01-28-2008, 03:46 PM#3
chobibo
Thanks MaD[Lion], I already knew that using structs I could create 2-d arrays but I wasn't sure if it would exceed the 2^13 limit. I was hoping to create a 8190 x 8190 2-d array using structs for storing data, guess I have to use GC after all lol. Thanks a lot MaD[Lion]!
Edit: I think its 90 x 91 elements.
01-28-2008, 04:27 PM#4
PipeDream
actually needing that much data is going to end poorly.. I hope you're only using it sparsely.
01-28-2008, 04:44 PM#5
chobibo
I'm not gonna use every element, just need it to catch data since i'll be using H2I as string keys. Kinda like what CSData does. I have a code which does this but its on another thread. Thanks man for the tip and NewGen :)
01-28-2008, 05:39 PM#6
Strilanc
You might my BigArray structure, which can theoretically hold up to 8192^2 elements, useful (until Vex releases a stable newgen with a similar functionality built in):
http://www.scumedit.net/forum/showthread.php?t=2663

If you want the accesses to be 2D just write another get function that translates the coordinates appropriately.
01-28-2008, 05:56 PM#7
DiscipleOfLife
If you are on crack you can use this:
(altough you will prolly need to modify it to support as big integers as H2I returns) (except if you use H2I-0x0000...)
Collapse JASS:
//==============================================================================
//  XY (positive) Integer Array by DiscipleOfLife -- v1.0
//==============================================================================
library XYIA initializer init
// x € [0, 1530]
// y € [0, 1530]
// stored integer € [0, 899]
// can store a maximum of 23450900 integers
globals
    private constant string INITIALSTRING="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
    private string array thewais
    private constant integer OFFSET=100
    private constant integer VALENGTH=3        // how long integers you can store
    private constant integer YMAX=860/VALENGTH
endglobals
function SetXYInteger takes integer x, integer y, integer value returns nothing
    local integer a=x*(y/YMAX)    //from 1530 to 8191
    local integer b=y-(y/YMAX)*YMAX    //from 1530 to 215
    set thewais[a]=SubString(thewais[a],0,b*VALENGTH)+I2S(value+OFFSET)+SubString(thewais[a],(b+1)*VALENGTH,YMAX*VALENGTH)
endfunction
function GetXYInteger takes integer x, integer y returns integer
    local integer b=y-(y/YMAX)*YMAX    //from 1530 to 215
    return S2I(SubString(thewais[x*(y/YMAX)],b*VALENGTH,(b+1)*VALENGTH)) - OFFSET
endfunction
private function init takes nothing returns nothing
    local integer i=0
    loop
        exitwhen i>8190
        set thewais[i]=INITIALSTRING
        set i=i+1
    endloop
endfunction
endlibrary 
I tested this for a few thousand combinations of x/y/stored value so I think it works but Im not 100% sure. Take note that this leaks extremely big strings.
01-28-2008, 06:22 PM#8
chobibo
Thanks strilanc im gonna try it.
01-28-2008, 07:51 PM#9
MaD[Lion]
H2I is best with GC. cus the handle integer is big. But a combination of H2I GC and Struct makes it safe
01-29-2008, 02:10 AM#10
PipeDream
FWIW we tried trigger arrays awhile ago and they were slower than gamecache. TriggerEvaluate is a monster which creates a whole new VM instance.