HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

2D-array of 256x256

02-02-2008, 12:33 AM#1
Zandose
As the title says how would I make a 2D-array of 256x256? Would it be safe to create 256 structs with a array size of 256 each? I could also link 8 to 9 integer arrays and use some math formula to access what I need.
02-02-2008, 01:28 AM#2
PipeDream
Gamecache
02-02-2008, 01:38 AM#3
Vexorian
You can't have 65536 (256x256) but with latest beta jasshelper you can have 65Kish (the ish is a consequence of Jass' bug that removes an index and for the matter one vJass index has to be wasted on null) . So, you can't have a 256x256 array in vJass, but you can have a 255x256 one.
02-02-2008, 01:48 AM#4
Zandose
Quote:
Originally Posted by Vexorian
You can't have 65536 (256x256) but with latest beta jasshelper you can have 65Kish (the ish is a consequence of Jass' bug that removes an index and for the matter one vJass index has to be wasted on null) . So, you can't have a 256x256 array in vJass, but you can have a 255x256 one.

I'll look into that. Is there anything bad about about creating 256 structs with a integer array of 256 (or static?).
02-02-2008, 02:52 AM#5
PipeDream
yes, it won't work.
02-02-2008, 03:09 AM#6
Zandose
Quote:
Originally Posted by PipeDream
yes, it won't work.
So far it's been working for me. Try this on a 32x32 map.
Collapse JASS:
scope Reset
//Type "-reset" ingame to use
//Changes all the terrain to ice then resets it

globals
    private constant integer MAP_SIZE_X = 32 //Width: Left/Right
    private constant integer MAP_SIZE_Y = 32 //Height: Up/Down
endglobals

private struct terrain  
    integer array t[MAP_SIZE_X] //Terrain Types
endstruct

private struct variance
    integer array v[MAP_SIZE_X] //Terrain Variances
endstruct

globals
    terrain array te
    variance array va
endglobals

private function Actions takes nothing returns nothing
    local integer array i
    local rect r = GetWorldBounds()
    local real x = GetRectMinX(r)
    local real y = GetRectMaxY(r)
    call RemoveRect(r)
    call SetTerrainType(0, 0, 'Iice', -1, 17, 1)
    call TriggerSleepAction(5.00)
    set i[1] = 0 //X
    set i[2] = 0 //Y
    loop
        loop
            call SetTerrainType(x + (i[1] * 128), y - (i[2] * 128), te[i[2]].t[i[1]], va[i[2]].v[i[1]], 1, 1)
            set i[1] = i[1] + 1
            exitwhen i[1] == MAP_SIZE_X + 1
        endloop
        set i[1] = 0
        set i[2] = i[2] + 1
        exitwhen i[2] == MAP_SIZE_Y + 1
    endloop
    call BJDebugMsg("Terrain has been reset")
endfunction

public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local integer array i
    local rect r = GetWorldBounds()
    local real x = GetRectMinX(r)
    local real y = GetRectMaxY(r)
    call RemoveRect(r)
    call TriggerRegisterPlayerChatEvent(trig, Player(0), "-reset", true )
    call TriggerAddAction(trig, function Actions)
    set i[1] = 0
    set i[2] = 0
    loop
        set te[i[2]] = terrain.create()
        set va[i[2]] = variance.create()
        loop
            set te[i[2]].t[i[1]] = GetTerrainType(x + (128 * i[1]), y - (128 * i[2]))
            set va[i[2]].v[i[1]] = GetTerrainVariance(x + (128 * i[1]), y - (128 * i[2]))
            set i[1] = i[1] + 1
            exitwhen i[1] == MAP_SIZE_X + 1
        endloop
        set i[1] = 0
        set i[2] = i[2] + 1
        exitwhen i[2] == MAP_SIZE_Y + 1
    endloop
endfunction

endscope