private function init takes nothing returns nothing
local trigger BarTool = CreateTrigger( )
local region enterbar = CreateRegion()
local rect r = Rect(1408.0, 2144.0, 1888.0, 2368.0)
call RegionAddRect(enterbar, r)
call TriggerRegisterEnterRegion(BarTool, enterbar, null)
call TriggerAddCondition( BarTool, Condition( function BarEnter ) )
call TriggerAddAction( BarTool, function BarEnterNice )
set BarTool = null
endfunction
globals
//Recycle TempRect each trigger. When you do "RegionAddRect" the region permanently
//remembers the rect so you are free to set TempRect to a new rect each time.
rect TempRect = Rect(0.,0.,0.,0.)
endglobals
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
local region r = CreateRegion()
//notice the native command "SetRect". this is helpful.
call SetRect(TempRect,1408., 2144., 1888., 2368.)
call RegionAddRect(r, TempRect)
call TriggerRegisterEnterRegion(t, r, null)
//make sure that you do RemoveRegion(GetTriggeringRegion()), TriggerClearActions(GetTriggeringTrigger()
//and DestroyTrigger(GetTriggeringTrigger()) when/if you are done with this trigger.
//if you never destroy the trigger/region, you don't have to set these next two to null:
set r = null
set t = null
//Combine trigger conditions with trigger actions because you're leaking 3 handles
//per trigger. This should be:
call TriggerAddAction(t,function BarEnter)
//and within function BarEnter you type:
if(BarEnter Conditions)then
call BarEnterNice()
endif
//That way you only need an action handle per trigger instead of 2 condition handles
//and an action handle.
endfunction
//Combine trigger conditions with trigger actions because you're leaking 3 handles
//per trigger. This should be:
TriggerRemoveAction()
(and null them, and TriggerClearActions() doesn't help with the handle leak as far as I know) whereas you don't need to remove trigger conditions.TriggerEvaluate()
which is much faster than TriggerExecute()
. Plus, most systems use:if TriggerEvaluate(t) then
call TriggerExecute(t)
endif
return false
)whereas you don't need to remove trigger conditions.
triggeraction
, why don't you need to remove triggercondition
?TriggerEvaluate
defaults true, anway. And if more people started using triggeraction
instead of triggercondition
then those systems could be updated without the evaluater.TriggerEvaluate
is faster than TriggerExecute
, is the native event-driven execution of the trigger faster, as well? And wouldn'tTriggerExecute
be faster if replaced with ExecuteFunc
? But this is me thinking rationally, something blizzard clearly skipped on with many of their codes.If there are no conditions, TriggerEvaluate defaults true, anway. And if more people started using triggeraction instead of triggercondition then those systems could be updated without the evaluater.
If using TriggerEvaluate is faster than TriggerExecute , is the native event-driven execution of the trigger faster, as well? And wouldn't TriggerExecute be faster if replaced with ExecuteFunc ? But this is me thinking rationally, something blizzard clearly skipped on with many of their codes.
globals
rect BarEnter = Rect(0.,0.,0.,0.)
endglobals
scope BarEnter initializer init
private function enter takes nothing returns nothing
local player p = GetOwningPlayer(GetTriggerUnit())
call BJDebugMsg("entering: The Drunken Panda tavern")
call SetLightIndoors(p)
set p = null
endfunction
private function cond takes nothing returns boolean
local integer LoopA = 1
loop
exitwhen LoopA > 12
if GetTriggerUnit() == PlayerHero[LoopA] then
if isIndoor[LoopA] == false then
call enter()
return false
endif
return false
endif
set LoopA = LoopA + 1
endloop
return false
endfunction
private function init takes nothing returns nothing
local trigger BarTool = CreateTrigger( )
local region enterbar = CreateRegion()
call SetRect(BarEnter, 1408., 2200., 1880., 2210.)
call RegionAddRect(enterbar, BarEnter)
call TriggerRegisterEnterRegion(BarTool, enterbar, null)
call TriggerAddCondition( BarTool, Condition( function cond ) )
set BarTool = null
set BarEnter = null
endfunction
endscope
rect BarEnter
in any other trigger, then you should remove it. call RemoveRect(BarEnter)
in the Init function after RegionAddRect()
.Ok, so the code mechanism for registering actions causes a leak because each new code reference is like creating a new code object? I get that once you create a Condition any further attempts to create that condition would just reference the same one you already made, but codes not? That would be problematic for people using timers orYou don't need to remove triggerconditions because they don't leak; that's all there is to it.
ForGroup
calls, wouldn't it?globals
rect BarEnter = Rect(0.,0.,0.,0.)
endglobals
scope BarEnter initializer init
private function enter takes nothing returns nothing
local player p = GetTriggerPlayer() //returns the same player as owner of triggering unit.
call BJDebugMsg("entering: The Drunken Panda tavern")
call SetLightIndoors(p) //Why are you setting a variable if you're only going to use it once? Just inline it to SetLightIndoors(GetTriggerPlayer())
//set p = null <!-- nulling players is a waste of time. They are never destroyed, so you can have a million pointers to them. -->
endfunction
private function cond takes nothing returns boolean
local integer LoopA = 1
local unit trigUnit = GetTriggerUnit() //don't call GetTriggerUnit() so many times, just make it a variable.
loop
//Why do you have the players assigned to 1-12? It's always easier to zap Player(0) to array[0].
exitwhen LoopA > 12
if trigUnit == PlayerHero[LoopA] then
if not isIndoor[LoopA] then
call enter()
//return false <!-- no need for this -->
endif
exitwhen(true) //return false <!-- don't do a return. Just exit the loop so that the function can finish and set trigUnit to null. -->
endif
set LoopA = LoopA + 1
endloop
set trigUnit = null
return false
endfunction
private function init takes nothing returns nothing
local trigger BarTool = CreateTrigger( )
local region enterbar = CreateRegion()
call SetRect(BarEnter, 1408., 2200., 1880., 2210.)
call RegionAddRect(enterbar, BarEnter)
call TriggerRegisterEnterRegion(BarTool, enterbar, null)
call TriggerAddCondition( BarTool, Condition( function cond ) )
//set BarTool = null <!-- Unless you plan to destroy the trigger, don't set it to null. -->
//set BarEnter = null <!-- Same as above. If the trigger doesn't need destroying, this region doesn't need nulling. -->
endfunction
endscope
exitwhen true
exits the loop immediately. I'm not sure if just writing exitwhen is enough, but the thing is it's often not the best idea to return out of a function so early, because you might skip over something (such as, in this case, the need to null the local unit).