- Joined
- Feb 25, 2013
- Messages
- 16
Hey folks
This is related to a previous post of mine: here
I have a script that generates 4 Rects per player and saves them to a global hashtable (gg_tbl_playerRegions). This works fine
The problem occurs when I want to iterate this hashtable and add Trigger Events for the regions. It is as if the hashtable has not been populated before my Event-generation is run.
This DebugMsg just displays "Adding event: 0" all the time, but it should bet he ID of the region.
What am I doing wrong? (I'm open to hear about leak-problems, but that's not the issue at hand here I think
)
Code for generating regions:
Code for generating Events:
This is related to a previous post of mine: here
I have a script that generates 4 Rects per player and saves them to a global hashtable (gg_tbl_playerRegions). This works fine
The problem occurs when I want to iterate this hashtable and add Trigger Events for the regions. It is as if the hashtable has not been populated before my Event-generation is run.
This DebugMsg just displays "Adding event: 0" all the time, but it should bet he ID of the region.
JASS:
call BJDebugMsg("Adding event: " + I2S(GetHandleId(toEnter)))
What am I doing wrong? (I'm open to hear about leak-problems, but that's not the issue at hand here I think
Code for generating regions:
JASS:
globals
trigger gg_trg_addRegions
hashtable gg_tbl_playerRegions = InitHashtable()
endglobals
function AdjustLocation takes location loc, integer i returns location
local integer array multiX
local integer array multiY
set multiX[0] = 0
set multiX[1] = 1
set multiX[2] = 0
set multiX[3] = -1
set multiY[0] = 1
set multiY[1] = 0
set multiY[2] = -1
set multiY[3] = 0
return Location(GetLocationX(loc)+(udg_PlayerRgnOffset * multiX[i]),GetLocationY(loc)+(udg_PlayerRgnOffset * multiY[i]))
endfunction
function GenerateSpawnRegions takes nothing returns nothing
local unit u = GetEnumUnit()
local rect array rects_Spawn
local real rectRadius = 100.0
local location uLoc = GetUnitLoc(u)
local integer count = 0
local location center
local location min
local location max
loop
exitwhen count > 3
set center = AdjustLocation(uLoc, count)
set min = Location(GetLocationX(center)-rectRadius,GetLocationY(center)-rectRadius)
set max = Location(GetLocationX(center)+rectRadius,GetLocationY(center)+rectRadius)
call SaveRectHandle(gg_tbl_playerRegions, GetHandleId(GetOwningPlayer(u)), count, RectFromLoc(min, max))
set count = count + 1
endloop
endfunction
function Trig_AddRegions_Actions takes nothing returns nothing
call ForGroupBJ( GetUnitsOfTypeIdAll(udg_CopterType), function GenerateSpawnRegions )
endfunction
//===========================================================================
function InitTrig_AddRegions takes nothing returns nothing
set gg_trg_AddRegions = CreateTrigger( )
call TriggerAddAction( gg_trg_AddRegions, function Trig_AddRegions_Actions )
endfunction
Code for generating Events:
JASS:
function Trig_UnitsEnterRegions_Actions takes nothing returns nothing
//call BJDebugMsg("A unit entered the region!")
endfunction
function AddEventForRegionToTrigger takes nothing returns nothing
local integer rectI = 0
local integer rectMax = 3
local rect toEnter
loop
exitwhen rectI > rectMax
set toEnter = LoadRectHandle(gg_tbl_playerRegions, GetHandleId(GetEnumPlayer()), rectI )
call BJDebugMsg("Adding event: " + I2S(GetHandleId(toEnter)))
call TriggerRegisterEnterRectSimple( gg_trg_UnitsEnterRegions, toEnter)
set rectI = rectI + 1
endloop
endfunction
//===========================================================================
function InitTrig_UnitsEnterRegions takes nothing returns nothing
set gg_trg_UnitsEnterRegions = CreateTrigger( )
call BJDebugMsg("TRIGGER INITIALIZED")
call ForForce( GetPlayersAll(), function AddEventForRegionToTrigger )
call TriggerAddAction( gg_trg_UnitsEnterRegions, function Trig_UnitsEnterRegions_Actions )
endfunction