• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] Storing rects in hashtable

Status
Not open for further replies.
Hello !

I need to store ~600 regions (made with the region editor directly on the map) in a hashtable (let s say they are all called Region_1 to Region_600)

I wanna use a loop to easily store them all with custom script, but I'm not sure how write it.
Here it would be for the rect named Region_15.

vJASS:
call SaveRectHandleBJ( gg_rct_Region_15, udg_INTEGER, 1, udg_REGIONSCAMPAIGN )

how can I do something like that ?? :
vJASS:
call SaveRectHandleBJ( gg_rct_Region_(GetForLoopIndexA()), GetForLoopIndexA(), 1, udg_REGIONSCAMPAIGN )

Thanks !!!


EDIT : Oh and btw, is there a limit of Events in a trigger ? (thoses 600 rects will be added as UnitLeaves/Enters Region events)
 
Last edited:
Level 37
Joined
Jul 22, 2015
Messages
3,485
Unless you create the regions in the actual code, you won't be able to do something like gg_rct_Region_i.

As far as I know, this won't compile:
JASS:
function SaveRegions takes nothing returns nothing
    local integer i = 0

    loop
        exitwhen i > numberOfRegions
        call SaveRectHandle(hash, GetHandleId(gg_rct_Region_i), 0, gg_rct_Region_i)
        set i = i + 1
    endloop
endfunction
 
Last edited:
Fun little trick:

When you create rects using the region palette, they are actually generated in the war3map.j consecutively. So the agent stack will look something like this:
Stack.png

So if we want to store all the rects using a loop, we can simply loop through the handle ID's, typecast them to rects, and store them.

It would look something like this:
JASS:
//**
//*  Converts an agent ID to a rect, if possible. If the
//*  agent for that ID is not a rect, it will return null.
//*
function AgentIdToRect takes integer agentID returns rect
    call SaveFogStateHandle(udg_REGIONSCAMPAIGN, -1, agentID, ConvertFogState(agentID))
    return LoadRectHandle(udg_REGIONSCAMPAIGN, -1, agentID)
endfunction

//**
//*  Stores all rects in the hashtable udg_REGIONSCAMPAIGN.
//*  The parent key is 1 and the child key is the rect number,
//*  starting from 1 and ending at total number of rects.
//*
function StoreRectsInHashtable takes nothing returns nothing
    local integer currentStackId = 0x100000
    local integer rectId = 0
    local integer rectNumber = 1
    local rect currentRect = null

    // Find the first region in the stack
    loop
        exitwhen AgentIdToRect(currentStackId) != null
        currentStackId = currentStackId + 1
    endloop

    // Store the rects in the hashtable
    rectId = currentStackId
    loop
        currentRect = AgentIdToRect(rectId)
        exitwhen currentRect == null

        call SaveRectHandle(udg_REGIONSCAMPAIGN, 1, rectNumber, currentRect)
        rectId = rectId + 1
        rectNumber = rectNumber + 1
    endloop

    // Cleanup
    set currentRect = null
endfunction

Untested. A few things to note:
  • Right now, I store it into udg_REGIONSCAMPAIGN and I give it a parent key of 1, and a child key of the rect number. (e.g. Region_221 will have a child key 221).
  • It is not 100% stable. Technically I could make a map where this wouldn't work. But for most maps where you haven't tampered with the default editor functions, it should work.
  • I haven't tested it and I haven't compiled it. It is up to you test it and see if it works out as you want it to. :)
Good luck! It might be easier to do it the old fashioned copy'and'paste way, but I thought I'd share this since it is interesting and can prevent a lot of code bloat.
 
Status
Not open for further replies.
Top