I'm just now making the transition from GUI to JASS, and I have a problem with a trigger that transports a unit from one rect to another upon entering the first rect. I want to apply it in a few different places, and I want to make it as general as possible so that I don't have to write and call different functions for each instance.
Here's what it looks like now, it works but it's only for one of the instances. I'm just using one of the regions for testing purposes right now.
So I put all of the entry rects into an array and all of the rects used for exits in another. The idea was to get the index of the entry rect so I could use that number to get a rect with the same index from the other array with this function:
It didn't really work out since from what I understand there is no way to check for the triggering rect, just regions with GetTriggeringRegion(). At first I had the BossEntranceRegionCheck take a region as an argument instead and just converting the entry rect into a region. However this lead to some other problems, since to my knowledge you can't get the center of a region, just the center of a rect and I can't seem to find a way to turn the region back into a rect either.
I feel like this isn't that hard and that I'm likely missing something obvious, but I'm not sure what.
Here's what it looks like now, it works but it's only for one of the instances. I'm just using one of the regions for testing purposes right now.
JASS:
function BossEntranceConditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)
endfunction
function BossEntranceHandlerfunc takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit u = LoadUnitHandle(udg_bossEntranceHash, GetHandleId(t), 0)
call ShowUnit(u, true)
call SelectUnitAddForPlayer( u, GetOwningPlayer(u) )
call PauseTimer(t)
call DestroyTimer(t)
set t = null
set u = null
call RemoveUnit(u)
endfunction
function BossEntranceActions01 takes nothing returns nothing
local location l = GetRectCenter(udg_bossEntranceTargets[1])
local unit u = GetTriggerUnit()
local timer t = CreateTimer()
call ShowUnit(u, false)
call SetUnitPositionLoc(u, l)
call SaveUnitHandle(udg_bossEntranceHash, GetHandleId(t), 0, u)
call PanCameraToTimedLocForPlayer(GetOwningPlayer(u), l, 0.25)
call TimerStart(t, 0.25, false, function BossEntranceHandlerfunc)
set t = null
set l = null
set u = null
call RemoveLocation(l)
call RemoveUnit(u)
endfunction
//===========================================================================
function InitTrig_Boss_Entrances takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterEnterRectSimple( t, udg_bossEntranceRegions[1])
call TriggerAddCondition( t, Condition( function BossEntranceConditions ) )
call TriggerAddAction( t, function BossEntranceActions01 )
endfunction
JASS:
function BossEntranceRegionCheck takes rect r returns integer
local integer i = 0
loop
exitwhen i > 20
if r == udg_bossEntranceRegions[i] then
return i
endif
set i = i + 1
endloop
set r = null
return 0
endfunction
I feel like this isn't that hard and that I'm likely missing something obvious, but I'm not sure what.