• 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.

Improving GUI Triggers with JASS/vJASS

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
Hi! I'm working hard right now to improve the triggers of a TD I'm making, mostly to avoid BJ's and 'condition functions'. I already tried to improve as much as I was able, I'd like to know what else I can do to improve them even more.

This is one of my most repetitive triggers. I use these to move creeps to a random road when they reach an intersection. I save the amount of intersections they've reached in a Hashtable.

JASS:
function Trig_M3_Copy_Actions takes nothing returns nothing
    set udg_TUnit = GetTriggerUnit()
    if GetOwningPlayer(udg_TUnit) == Player(PLAYER_NEUTRAL_AGGRESSIVE) then
    set udg_TInt = GetHandleId(GetTriggerUnit())
    set udg_TInt2 = LoadInteger(udg_Hash, udg_TInt, 5)
    call SaveInteger(udg_Hash, udg_TInt, 5, (udg_TInt2 + 1))
    set udg_Regions[1] = gg_rct_M2
    set udg_Regions[2] = gg_rct_C2
    set udg_Regions[3] = gg_rct_M4
    set udg_TInt = GetRandomInt(1, 3)
    set udg_TPoint = Location(GetRectCenterX(udg_Regions[udg_TInt]), GetRectCenterY(udg_Regions[udg_TInt]))
    call IssuePointOrderLoc(udg_TUnit, "attack", udg_TPoint)
    call RemoveLocation(udg_TPoint)
    endif
endfunction

//===========================================================================
function InitTrig_M3_Copy takes nothing returns nothing
    set gg_trg_M3_Copy = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_M3_Copy, gg_rct_M3 )
    call TriggerAddAction( gg_trg_M3_Copy, function Trig_M3_Copy_Actions )
endfunction

I use 4 of these to prevent players join into another player area.
JASS:
function Trig_Red_Boundaries_Copy_Actions takes nothing returns nothing
    set udg_TUnit = GetTriggerUnit()
    set udg_Player = GetOwningPlayer(udg_TUnit)
    if udg_Player != Player(PLAYER_NEUTRAL_AGGRESSIVE) or udg_Player != Player(0) then
    set udg_TPoint = GetStartLocationLoc(GetPlayerStartLocation(udg_Player))
    call SetUnitPositionLoc( udg_TUnit, udg_TPoint )
    call RemoveLocation(udg_TPoint)
    set udg_TForce = GetForceOfPlayer(udg_Player)
    call DisplayTextToForce( udg_TForce, ( "|cffff0000Error:|r " + "You can't enter other player area." ) )
    call DestroyForce(udg_TForce)
    endif
endfunction

//===========================================================================
function InitTrig_Red_Boundaries_Copy takes nothing returns nothing
    set gg_trg_Red_Boundaries_Copy = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Red_Boundaries_Copy, gg_rct_RedPlayer )
    call TriggerAddAction( gg_trg_Red_Boundaries_Copy, function Trig_Red_Boundaries_Copy_Actions )
endfunction
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Oh, you mean, setting the point instantly in the order and not in a Point Variable? And, would it work to check the OrderID of my triggered orders and use it instead of te string, wich is known as slower?

If I don't set the location to TPoint, wouldn't it leak to GetRectCenterX and GetRectCenterY?

What about also using locals? I've never used them, so, here's a first try.

JASS:
function Trig_M3_Conditions takes nothing returns boolean 
    return GetOwningPlayer(GetTriggerUnit()) == Player(PLAYER_NEUTRAL_AGGRESSIVE)
endfunction

function Trig_M3_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer i = GetHandleId(u)
    local integer i2 = LoadInteger(udg_Hash, i, 5)
    local integer i3 = GetRandomInt(1,3)
    call SaveInteger(udg_Hash, i, 5, (i2 + 1))
    call IssuePointOrderById(u, 851983, udg_XReals[i3], udg_YReals[i3])
    endif
    set u = null
endfunction

//===========================================================================
function InitTrig_M3 takes nothing returns nothing
    set gg_trg_M3 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple(gg_trg_M3, gg_rct_M3)
    call TriggerAddConditions(gg_trg_M3, function Trig_M3_Conditions)
    call TriggerAddAction(gg_trg_M3, function Trig_M3_Actions)
    set udg_XReals[1] = GetRectCenterX(gg_rct_M2)
    set udg_YReals[1] = GetRectCenterY(gg_rct_M2)
    set udg_XReals[2] = GetRectCenterX(gg_rct_C2)
    set udg_YReals[2] = GetRectCenterY(gg_rct_C2)
    set udg_XReals[3] = GetRectCenterX(gg_rct_M4)
    set udg_YReals[3] = GetRectCenterY(gg_rct_M4)
endfunction

Edit: Thanks Arhow
Edit: Thanks Maker
 
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765
GetRectCenterX and Y return reals, not locations, so they dont leak

also, a region != a rect. you set a region to a rect, that should return a syntax error last i checked. switch the variable type to rect array
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
JASS:
function Trig_M3_Conditions takes nothing returns boolean 
    return GetOwningPlayer(GetTriggerUnit()) == Player(PLAYER_NEUTRAL_AGGRESSIVE)
endfunction

function Trig_M3_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer i = GetHandleId(u)
    local integer i2 = LoadInteger(udg_Hash, i, 5)
    local integer i3 = GetRandomInt(1,3)
    call SaveInteger(udg_Hash, i, 5, (i2 + 1))
    // Use u below and not udg_TUnit?
    call IssuePointOrderById(u, 851983, arrayX[i3]), arrayY[i3]))
    set u = null
endfunction

//===========================================================================
function InitTrig_M3 takes nothing returns nothing
    set gg_trg_M3 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple(gg_trg_M3, gg_rct_M3)
    call TriggerAddConditions(gg_trg_M3, function Trig_M3_Conditions)
    call TriggerAddAction(gg_trg_M3, function Trig_M3_Actions)
    // you can use a global real arrays here containing the center x and y coordinates
endfunction
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,243
Would it be possible to, somehow, make all the triggers work with one trigger alone?

Yes, it is possible.

There is GetTriggeringRegion function if you need to know which region was entered.. You can store some integer for each region into a hashtable and then load the integer with LoadInteger(udg_hash, GetHandleId(GetTriggeringRegion()), childKey)

The integer tells which indexes in the real array the region uses.
 
Level 6
Joined
Jun 19, 2010
Messages
143
call TriggerRegisterEnterRectSimple( gg_trg_M3_Copy, gg_rct_M3 ) I doubt your script won't work, JassHelper showed me an error when saving the map. At that time, I still kept using the map region but then realized an error. rect in vjass is not a GUI region. And if you want to use the same variables in those functions, you can use either global variables or private variables, private real x,private real y.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I have a problem. The creeps spawn and move directly towards the Goal.

EDIT: I was adding data to rects, and not regions. Created them manually and placed data manually, but Creeps still run towards the goal. The variable "Roads" is giving me 0, even when it has 1, 2, 3, 4, and 5 saved on different regions =/

EDIT: Nevermind, I was creating the Hashtable in the Map Initialization trigger, and all the data I was creating together with these regions and rects had nowhere to save. Created the Hash in this trigger and everything works ok now. Thansk everyone!

Here's the code for anyone to look and help to improve it even more. I'd be really greatefull for that.

PD: Text Blocks are just for testing purposes.
JASS:
function CreepMovement_Conditions takes nothing returns boolean 
    return GetOwningPlayer(GetTriggerUnit()) == Player(PLAYER_NEUTRAL_AGGRESSIVE)
endfunction

function CreepMovement_Actions takes nothing returns nothing
// Locals
    local region Reg = GetTriggeringRegion()                        // Triggering Region
    local integer RegID = GetHandleId(Reg)                          // Region Handle ID
    local integer Roads = LoadInteger(udg_Hash, RegID, 0)           // Available Roads (For Random Int)
    local unit Creep = GetTriggerUnit()                             // Triggering Unit
    local integer CreepID = GetHandleId(Creep)                      // Unit Handle ID
    local integer Steps = (LoadInteger(udg_Hash, CreepID, 1) + 1)   // Number of Creep Steps + 1
    local integer i = GetRandomInt(1,Roads)                         // Random Choices
    local integer CBoolean = LoadInteger(udg_Hash, CreepID, 2)      // Unit is in Region C1, C2, C3 or C4.
    local real rx
    local real ry
        
// Functions
    call SaveInteger(udg_Hash, CreepID, 1, Steps)       // Steps Update
    if Steps > 11 and CBoolean == 1 then 
        set i = GetRandomInt(3,5)
    endif
    
    set rx = LoadReal(udg_Hash, RegID, i)
    set ry = LoadReal(udg_Hash, RegID, (i+5))
   
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, "----------------")
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, " ")
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, " ")
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, ("Region ID: " + I2S(RegID)))
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, ("Roads: " + I2S(Roads)))
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, ("Unit Name: " + GetUnitName(Creep)))
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, ("Unit ID: " + I2S(CreepID)))
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, ("Unit Steps: " + I2S(Steps)))
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, ("Random Int: " + I2S(i)))
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, ("CBoolean: " + I2S(CBoolean)))
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, ("Real X: " + R2S(rx)))
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, ("Real Y: " + R2S(ry)))
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, " ")
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, " ")
    call DisplayTimedTextToForce(GetPlayersAll(), 100.00, "----------------")
    
    call IssuePointOrder(Creep, "attack", rx, ry)   // Unit attack-move
        
    set Creep = null
    set Reg = null
endfunction

//===========================================================================
function InitTrig_CreepMovement takes nothing returns nothing
    set gg_trg_CreepMovement = CreateTrigger(  )
    
    set udg_Hash = InitHashtable()
    
    local integer i
    // X
    local real xM1 = GetRectCenterX(gg_rct_M1)
    local real xM2 = GetRectCenterX(gg_rct_M2)
    local real xM3 = GetRectCenterX(gg_rct_M3)
    local real xM4 = GetRectCenterX(gg_rct_M4)
    local real xM5 = GetRectCenterX(gg_rct_M5)
    local real xM6 = GetRectCenterX(gg_rct_M6)
    local real xM7 = GetRectCenterX(gg_rct_M7)
    local real xM8 = GetRectCenterX(gg_rct_M8)
    local real xM9 = GetRectCenterX(gg_rct_M9)
    local real xM10 = GetRectCenterX(gg_rct_M10)
    local real xM11 = GetRectCenterX(gg_rct_M11)
    local real xM12 = GetRectCenterX(gg_rct_M12)
    local real xC1 = GetRectCenterX(gg_rct_C1)
    local real xC2 = GetRectCenterX(gg_rct_C2)
    local real xC3 = GetRectCenterX(gg_rct_C3)
    local real xC4 = GetRectCenterX(gg_rct_C4)
    local real xGoal = GetRectCenterX(gg_rct_Goal)
    // Y
    local real yM1 = GetRectCenterY(gg_rct_M1)
    local real yM2 = GetRectCenterY(gg_rct_M2)
    local real yM3 = GetRectCenterY(gg_rct_M3)
    local real yM4 = GetRectCenterY(gg_rct_M4)
    local real yM5 = GetRectCenterY(gg_rct_M5)
    local real yM6 = GetRectCenterY(gg_rct_M6)
    local real yM7 = GetRectCenterY(gg_rct_M7)
    local real yM8 = GetRectCenterY(gg_rct_M8)
    local real yM9 = GetRectCenterY(gg_rct_M9)
    local real yM10 = GetRectCenterY(gg_rct_M10)
    local real yM11 = GetRectCenterY(gg_rct_M11)
    local real yM12 = GetRectCenterY(gg_rct_M12)
    local real yC1 = GetRectCenterY(gg_rct_C1)
    local real yC2 = GetRectCenterY(gg_rct_C2)
    local real yC3 = GetRectCenterY(gg_rct_C3)
    local real yC4 = GetRectCenterY(gg_rct_C4)
    local real yGoal = GetRectCenterY(gg_rct_Goal)
    
    local region RegR1 = CreateRegion()
    call RegionAddRect(RegR1, gg_rct_R1)
    set i = GetHandleId(RegR1)
    call SaveInteger(udg_Hash, i, 0, 1)
    call SaveReal(udg_Hash, i, 1, xM1)
    call SaveReal(udg_Hash, i, 6, yM1)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegR1, null)
    
    local region RegR2 = CreateRegion()
    call RegionAddRect(RegR2, gg_rct_R2)
    set i = GetHandleId(RegR2)
    call SaveInteger(udg_Hash, i, 0, 1)
    call SaveReal(udg_Hash, i, 1, xM1)
    call SaveReal(udg_Hash, i, 6, yM1)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegR2, null)
    
    local region RegR3 = CreateRegion()
    call RegionAddRect(RegR3, gg_rct_R3)
    set i = GetHandleId(RegR3)
    call SaveInteger(udg_Hash, i, 0, 1)
    call SaveReal(udg_Hash, i, 1, xM4)
    call SaveReal(udg_Hash, i, 6, yM4)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegR3, null)
    
    local region RegR4 = CreateRegion()
    call RegionAddRect(RegR4, gg_rct_R4)
    set i = GetHandleId(RegR4)
    call SaveInteger(udg_Hash, i, 0, 1)
    call SaveReal(udg_Hash, i, 1, xM4)
    call SaveReal(udg_Hash, i, 6, yM4)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegR4, null)
    
    local region RegR5 = CreateRegion()
    call RegionAddRect(RegR5, gg_rct_R5)
    set i = GetHandleId(RegR5)
    call SaveInteger(udg_Hash, i, 0, 1)
    call SaveReal(udg_Hash, i, 1, xM7)
    call SaveReal(udg_Hash, i, 6, yM7)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegR5, null)
    
    local region RegR6 = CreateRegion()
    call RegionAddRect(RegR6, gg_rct_R6)
    set i = GetHandleId(RegR6)
    call SaveInteger(udg_Hash, i, 0, 1)
    call SaveReal(udg_Hash, i, 1, xM7)
    call SaveReal(udg_Hash, i, 6, yM7)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegR6, null)
    
    local region RegR7 = CreateRegion()
    call RegionAddRect(RegR7, gg_rct_R7)
    set i = GetHandleId(RegR7)
    call SaveInteger(udg_Hash, i, 0, 1)
    call SaveReal(udg_Hash, i, 1, xM10)
    call SaveReal(udg_Hash, i, 6, yM10)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegR7, null)
    
    local region RegR8 = CreateRegion()
    call RegionAddRect(RegR8, gg_rct_R8)
    set i = GetHandleId(RegR8)
    call SaveInteger(udg_Hash, i, 0, 1)
    call SaveReal(udg_Hash, i, 1, xM10)
    call SaveReal(udg_Hash, i, 6, yM10)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegR8, null)
    
    local region RegM1 = CreateRegion()
    call RegionAddRect(RegM1, gg_rct_M1)
    set i = GetHandleId(RegM1)
    call SaveInteger(udg_Hash, i, 0, 2)
    call SaveReal(udg_Hash, i, 1, xM2)
    call SaveReal(udg_Hash, i, 2, xM12)
    call SaveReal(udg_Hash, i, 6, yM2)
    call SaveReal(udg_Hash, i, 7, yM12)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM1, null)
    
    local region RegM2 = CreateRegion()
    call RegionAddRect(RegM2, gg_rct_M2)
    set i = GetHandleId(RegM2)
    call SaveInteger(udg_Hash, i, 0, 3)
    call SaveReal(udg_Hash, i, 1, xM1)
    call SaveReal(udg_Hash, i, 2, xM3)
    call SaveReal(udg_Hash, i, 3, xC1)
    call SaveReal(udg_Hash, i, 6, yM1)
    call SaveReal(udg_Hash, i, 7, yM3)
    call SaveReal(udg_Hash, i, 8, yC1)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM2, null)
    
    local region RegM3 = CreateRegion()
    call RegionAddRect(RegM3, gg_rct_M3)
    set i = GetHandleId(RegM3)
    call SaveInteger(udg_Hash, i, 0, 3)
    call SaveReal(udg_Hash, i, 1, xM2)
    call SaveReal(udg_Hash, i, 2, xM4)
    call SaveReal(udg_Hash, i, 3, xC2)
    call SaveReal(udg_Hash, i, 6, yM2)
    call SaveReal(udg_Hash, i, 7, yM4)
    call SaveReal(udg_Hash, i, 8, yC2)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM3, null)
    
    local region RegM4 = CreateRegion()
    call RegionAddRect(RegM4, gg_rct_M4)
    set i = GetHandleId(RegM4)
    call SaveInteger(udg_Hash, i, 0, 2)
    call SaveReal(udg_Hash, i, 1, xM3)
    call SaveReal(udg_Hash, i, 2, xM5)
    call SaveReal(udg_Hash, i, 6, yM3)
    call SaveReal(udg_Hash, i, 7, yM5)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM4, null)
    
    local region RegM5 = CreateRegion()
    call RegionAddRect(RegM5, gg_rct_M5)
    set i = GetHandleId(RegM5)
    call SaveInteger(udg_Hash, i, 0, 3)
    call SaveReal(udg_Hash, i, 1, xM4)
    call SaveReal(udg_Hash, i, 2, xC2)
    call SaveReal(udg_Hash, i, 3, xM6)
    call SaveReal(udg_Hash, i, 6, yM4)
    call SaveReal(udg_Hash, i, 7, yC2)
    call SaveReal(udg_Hash, i, 8, yM4)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM5, null)
    
    local region RegM6 = CreateRegion()
    call RegionAddRect(RegM6, gg_rct_M6)
    set i = GetHandleId(RegM6)
    call SaveInteger(udg_Hash, i, 0, 3)
    call SaveReal(udg_Hash, i, 1, xM5)
    call SaveReal(udg_Hash, i, 2, xC3)
    call SaveReal(udg_Hash, i, 3, xM7)
    call SaveReal(udg_Hash, i, 6, yM5)
    call SaveReal(udg_Hash, i, 7, yC3)
    call SaveReal(udg_Hash, i, 8, yM7)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM6, null)
    
    local region RegM7 = CreateRegion()
    call RegionAddRect(RegM7, gg_rct_M7)
    set i = GetHandleId(RegM7)
    call SaveInteger(udg_Hash, i, 0, 2)
    call SaveReal(udg_Hash, i, 1, xM6)
    call SaveReal(udg_Hash, i, 2, xM8)
    call SaveReal(udg_Hash, i, 6, yM6)
    call SaveReal(udg_Hash, i, 7, yM8)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM7, null)
    
    local region RegM8 = CreateRegion()
    call RegionAddRect(RegM8, gg_rct_M8)
    set i = GetHandleId(RegM8)
    call SaveInteger(udg_Hash, i, 0, 3)
    call SaveReal(udg_Hash, i, 1, xM7)
    call SaveReal(udg_Hash, i, 2, xC3)
    call SaveReal(udg_Hash, i, 3, xM9)
    call SaveReal(udg_Hash, i, 6, yM7)
    call SaveReal(udg_Hash, i, 7, yC3)
    call SaveReal(udg_Hash, i, 8, yM9)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM8, null)
    
    local region RegM9 = CreateRegion()
    call RegionAddRect(RegM9, gg_rct_M9)
    set i = GetHandleId(RegM9)
    call SaveInteger(udg_Hash, i, 0, 3)
    call SaveReal(udg_Hash, i, 1, xM10)
    call SaveReal(udg_Hash, i, 2, xC4)
    call SaveReal(udg_Hash, i, 3, xM8)
    call SaveReal(udg_Hash, i, 6, yM10)
    call SaveReal(udg_Hash, i, 7, yC4)
    call SaveReal(udg_Hash, i, 8, yM8)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM9, null)
    
    local region RegM10 = CreateRegion()
    call RegionAddRect(RegM10, gg_rct_M10)
    set i = GetHandleId(RegM10)
    call SaveInteger(udg_Hash, i, 0, 2)
    call SaveReal(udg_Hash, i, 1, xM9)
    call SaveReal(udg_Hash, i, 2, xM11)
    call SaveReal(udg_Hash, i, 6, yM9)
    call SaveReal(udg_Hash, i, 7, yM11)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM10, null)
    
    local region RegM11 = CreateRegion()
    call RegionAddRect(RegM11, gg_rct_M11)
    set i = GetHandleId(RegM11)
    call SaveInteger(udg_Hash, i, 0, 3)
    call SaveReal(udg_Hash, i, 1, xM10)
    call SaveReal(udg_Hash, i, 2, xM12)
    call SaveReal(udg_Hash, i, 3, xC4)
    call SaveReal(udg_Hash, i, 6, yM10)
    call SaveReal(udg_Hash, i, 7, yM12)
    call SaveReal(udg_Hash, i, 8, yC4)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM11, null)
    
    local region RegM12 = CreateRegion()
    call RegionAddRect(RegM12, gg_rct_M12)
    set i = GetHandleId(RegM12)
    call SaveInteger(udg_Hash, i, 0, 3)
    call SaveReal(udg_Hash, i, 1, xM11)
    call SaveReal(udg_Hash, i, 2, xM1)
    call SaveReal(udg_Hash, i, 3, xC1)
    call SaveReal(udg_Hash, i, 6, yM11)
    call SaveReal(udg_Hash, i, 7, yM1)
    call SaveReal(udg_Hash, i, 8, yC1)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegM12, null)
    
    local region RegC1 = CreateRegion()
    call RegionAddRect(RegC1, gg_rct_C1)
    set i = GetHandleId(RegC1)
    call SaveInteger(udg_Hash, i, 0, 5)
    call SaveReal(udg_Hash, i, 1, xM12)
    call SaveReal(udg_Hash, i, 2, xM2)
    call SaveReal(udg_Hash, i, 3, xC2)
    call SaveReal(udg_Hash, i, 4, xC4)
    call SaveReal(udg_Hash, i, 5, xGoal)
    call SaveReal(udg_Hash, i, 6, yM12)
    call SaveReal(udg_Hash, i, 7, yM2)
    call SaveReal(udg_Hash, i, 8, yC2)
    call SaveReal(udg_Hash, i, 9, yC4)
    call SaveReal(udg_Hash, i, 10, yGoal)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegC1, null)
    
    local region RegC2 = CreateRegion()
    call RegionAddRect(RegC2, gg_rct_C2)
    set i = GetHandleId(RegC2)
    call SaveInteger(udg_Hash, i, 0, 5)
    call SaveReal(udg_Hash, i, 1, xC1)
    call SaveReal(udg_Hash, i, 2, xM3)
    call SaveReal(udg_Hash, i, 3, xM5)
    call SaveReal(udg_Hash, i, 4, xC3)
    call SaveReal(udg_Hash, i, 5, xGoal)
    call SaveReal(udg_Hash, i, 6, yC1)
    call SaveReal(udg_Hash, i, 7, yM3)
    call SaveReal(udg_Hash, i, 8, yM5)
    call SaveReal(udg_Hash, i, 9, yC3)
    call SaveReal(udg_Hash, i, 10, yGoal)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegC2, null)
    
    local region RegC3 = CreateRegion()
    call RegionAddRect(RegC3, gg_rct_C3)
    set i = GetHandleId(RegC3)
    call SaveInteger(udg_Hash, i, 0, 5)
    call SaveReal(udg_Hash, i, 1, xC2)
    call SaveReal(udg_Hash, i, 2, xM6)
    call SaveReal(udg_Hash, i, 3, xM8)
    call SaveReal(udg_Hash, i, 4, xC4)
    call SaveReal(udg_Hash, i, 5, xGoal)
    call SaveReal(udg_Hash, i, 6, yC2)
    call SaveReal(udg_Hash, i, 7, yM6)
    call SaveReal(udg_Hash, i, 8, yM8)
    call SaveReal(udg_Hash, i, 9, yC4)
    call SaveReal(udg_Hash, i, 10, yGoal)
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegC3, null)
    
    local region RegC4 = CreateRegion()
    call RegionAddRect(RegC4, gg_rct_C4)
    set i = GetHandleId(RegC4)
    call SaveInteger(udg_Hash, i, 0, 5)
    call SaveReal(udg_Hash, i, 1, xM11)
    call SaveReal(udg_Hash, i, 2, xC1)
    call SaveReal(udg_Hash, i, 3, xC3)
    call SaveReal(udg_Hash, i, 4, xM9)
    call SaveReal(udg_Hash, i, 5, xGoal)
    call SaveReal(udg_Hash, i, 6, yM11)
    call SaveReal(udg_Hash, i, 7, yC1)
    call SaveReal(udg_Hash, i, 8, yC3)
    call SaveReal(udg_Hash, i, 9, yM9)
    call SaveReal(udg_Hash, i, 10, yGoal)  
    TriggerRegisterEnterRegion(gg_trg_CreepMovement, RegC4, null)

    call TriggerAddCondition(gg_trg_CreepMovement, function CreepMovement_Conditions)
    call TriggerAddAction(gg_trg_CreepMovement, function CreepMovement_Actions)  
endfunction
 
Last edited:
Level 6
Joined
Jun 19, 2010
Messages
143
I don't know much about Hashtable. I worked with GUI many years before the release of warcraft patch 1.24, after it releases I even don't know how to work with it. How's different if Hashtable never exists in the world? Please let me. I need someone gives me a small exercise/sample to practice & check with. It seems to me Hashtable stores value. Can such a hashtable store many types of value, like itemId, unittypeId, unitId, many integer & real values?

JASS:
set i = GetHandleId(gg_rct_M1)
    call SaveInteger(udg_Hash, i, 0, 2)
    call SaveReal(udg_Hash, i, 1, xM2)
    call SaveReal(udg_Hash, i, 2, xM12)
    call SaveReal(udg_Hash, i, 6, yM2)
    call SaveReal(udg_Hash, i, 7, yM12)

It seems here you load the xM set x = LoadReal(udg_Hash, RegID, i)
Just wonder how the system knows which xM to load correctly & set to x? what if it loads xM11 where you want it to load xM4?

local hashtable Hash
private hashtable Hash
To define a private and local Hashtable instead of udg_Hash, are these correct?
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
udg_Hash means it's a Global variable Hash. udg_ prefix refers to any global variable (those created in GUI).

A Hashtable is a table able to hold any kind of value inside an index. It has infinite indexes (Arrays only hold up to 8190 or so)

We can see Columns as ParentKeys and Rows as ChildKeys.
JASS:
// Save 9 as 3 of 2 in Hash
0 1 2 3
1   |
2   |
3---9
4

// Saves '9' in Column #2 and Row#3

The thing is: The game creates a Handle for almost everything. Handle is an integer of about 10 characters, and you can reference anything in the game if you know the Handle.

What I did was save the X coordenates of possibe roads as 1, 2, 3 and Y coordenates as X+5 (6, 7, 8). There's the index "rows" which indicates the amount of available roads. That integer is equal to the amount of X and Y saved valued (If there are 2 rows, there are 2 X values, and 2 Y values). Then i set 'i = GetRandomInt(1,Rows)' i'm getting a random number between 1 and the number of rows (2, 3, 4, 5). Then I take the value in the RegionID and Row #i and Row#i+5 to get X and Y of the point.

"Just wonder how the system knows which xM to load correctly & set to x? what if it loads xM11 where you want it to load xM4?"

The system doesn't know. It just does what I tell it to. I order to load "i" and "i" is a random integer between 1 and 5. If it takes 4, it will load x4 and y4 from slots 4 and 9 of the Region ID which i set accordingly to work this way.
 
Status
Not open for further replies.
Top