local triggers: leak conditions & actions???

Grundy

Ultra Cool Member
Reaction score
35
i've never used local triggers much before but recently i have discovered that they work nicely for many triggered abilities. this particular one im working on can easily be done with 2 regular triggers but i decided to do it this way instead but not sure about leaks...and i used search and couldnt find the answer....
Code:
function Trig_Viper_Strike_Effect_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == GetAbilityId_ViperStrike()
endfunction

function Trig_Viper_Strike_Effect_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local location spot = GetSpellTargetLoc()
    call DestroyTrigger( GetTriggeringTrigger() )
    call ShowUnit( caster, false )
    call TriggerSleepAction( 0.30 )
    call SetUnitPositionLoc( caster, spot )
    call ShowUnitShow( caster )
    call SelectUnitAddForPlayer( caster, GetOwningPlayer( caster ) )
    set caster = null
    call RemoveLocation( spot )
endfunction

//===========================================================================
function Trig_Viper_Strike_Actions takes nothing returns nothing
    local trigger trg_Viper_Strike_Effect
    local unit caster = GetSpellAbilityUnit()
    local location spot = GetSpellTargetLoc()
    if( IsTerrainPathable(GetLocationX(spot), GetLocationY(spot), PATHING_TYPE_WALKABILITY) ) then
        set trg_Viper_Strike_Effect = CreateTrigger()
        call TriggerRegisterUnitEvent( trg_Viper_Strike_Effect, caster, EVENT_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( trg_Viper_Strike_Effect, Condition( function Trig_Viper_Strike_Effect_Conditions ) )
        call TriggerAddAction( trg_Viper_Strike_Effect, function Trig_Viper_Strike_Effect_Actions )
    else
        call SpellTargetErrorMessage( "|cffffcc00Must target walkable land.|r" )
    endif
    set caster = null
    call RemoveLocation(spot)
endfunction

function Trig_Viper_Strike_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == GetAbilityId_ViperStrike()
endfunction

//===========================================================================
function InitTrig_Viper_Strike takes nothing returns nothing
    set gg_trg_Viper_Strike = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Viper_Strike, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Viper_Strike, Condition( function Trig_Viper_Strike_Conditions ) )
    call TriggerAddAction( gg_trg_Viper_Strike, function Trig_Viper_Strike_Actions )
endfunction

does it leak an 'event' from the TriggerRegisterUnitEvent function?
does it leak a 'triggercondition' from the TriggerAddCondition function?
does it leak a 'triggeraction' from the TriggerAddAction function?
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Grundy said:
does it leak an 'event' from the TriggerRegisterUnitEvent function?
If it does there is nothing you can do about it. There is no TriggerRemoveEvent function ^^

Grundy said:
does it leak a 'triggercondition' from the TriggerAddCondition function?
Probably, there is a TriggerRemoveCondition. Also you are leaking a boolexpr in that event. Condition( function Trig_Viper_Strike_Effect_Conditions ).
I always try to avoid using conditions in dynamic triggers.

Grundy said:
does it leak a 'triggeraction' from the TriggerAddAction function?
Yes, use TriggerRemoveAction to fix this.
You have to store the boolexpr/triggeraction and triggercondition in a gamecache (handle vars) to destroy them later.

There is 2 function (TriggerClearConditions and
TriggerClearActions) that may let you destroy conditions and actions without storing them in a gamecache. BUT Ive never seen anyone using them, maybe becuse they doesn't fix the leaks. I don't know ^^
 

Grundy

Ultra Cool Member
Reaction score
35
phyrex1an said:
Probably, there is a TriggerRemoveCondition. Also you are leaking a boolexpr in that event. Condition( function Trig_Viper_Strike_Effect_Conditions ).
I always try to avoid using conditions in dynamic triggers.
if i did
Code:
...
local boolexpr vseCondition = Condition( function Trig_Viper_Strike_Effect_Conditions )
...
call TriggerAddCondition( trg_Viper_Strike_Effect, vseCondition )
...
call DestroyBoolExpr( vseCondition )
...
would that fix the leak?

Yes, use TriggerRemoveAction to fix this.
You have to store the boolexpr/triggeraction and triggercondition in a gamecache (handle vars) to destroy them later.
what functions do you use to destroy them later?

There is 2 function (TriggerClearConditions and
TriggerClearActions) that may let you destroy conditions and actions without storing them in a gamecache. BUT Ive never seen anyone using them, maybe becuse they doesn't fix the leaks. I don't know ^^
i thought those functions only took the conditions and actions out of the trigger, not free up the memory and fix leaks. like.... say you have a puzzle and you remove 2 pieces of the puzzle, then you have a puzzle missing 2 pieces plus 2 pieces not connected, as in they still exist just somewhere not connected to everything else



====================================================
ok i just found this function called DestroyCondition to get rid of 1 leak but not sure about the rest...

Code:
...
local trigger trg_whatever = CreateTrigger()
local conditionfunc trgcondition = Condition( function blahblahblah )
call TriggerAddCondition( trg_whatever, trgcondition )
call DestroyCondition( trgcondition )
...
so im not leaking a boolexpr or a conditionfunc but i think its still leaking a triggercondition but i see no way to clean those up at all
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
I'm not very used to work with dynamic triggers with conditions, I avoid conditions as much as possible ^^

Anyway, I guess this will work. It requires the CScache system with these 2 functions added to it
Code:
function GetTableTriggerCondition takes string table,string field returns triggercondition
    return GetStoredInteger(CSCache(),table,field)
    return null
endfunction
function GetTableBoolExpr takes string table,string field returns boolexpr
    return GetStoredInteger(CSCache(),table,field)
    return null
endfunction

Code:
function Trig_Viper_Strike_Effect_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == GetAbilityId_ViperStrike()
endfunction

function Trig_Viper_Strike_Effect_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local location spot = GetSpellTargetLoc()
    local trigger t = GetTriggeringTrigger()
    local string s = GetAttachmentTable(t)
    call TriggerRemoveAction(t,GetTableTriggerAction(s, "ac"))
    call TriggerRemoveCondition(t,GetTableTriggerCondition(s, "co"))
    call DestroyBoolExpr(GetTableBoolExpr(s, "be"))
    call DestroyTrigger( t )
    call ClearTable(s)
    call ShowUnit( caster, false )
    call TriggerSleepAction( 0.30 )
    call SetUnitPositionLoc( caster, spot )
    call ShowUnitShow( caster )
    call SelectUnitAddForPlayer( caster, GetOwningPlayer( caster ) )
    call RemoveLocation( spot )
    
    set caster = null
    set t = null
    set spot = null
endfunction

//======================================================================  =====
function Trig_Viper_Strike_Actions takes nothing returns nothing
    local trigger trg_Viper_Strike_Effect
    local unit caster = GetSpellAbilityUnit()
    local location spot = GetSpellTargetLoc()
    local boolexpr b
    local string s 
    if( IsTerrainPathable(GetLocationX(spot), GetLocationY(spot), PATHING_TYPE_WALKABILITY) ) then
        set trg_Viper_Strike_Effect = CreateTrigger()
        set s = GetAttachmentTable(trg_Viper_Strike_Effect)
        set b = Condition( function Trig_Viper_Strike_Effect_Conditions )
        call TriggerRegisterUnitEvent( trg_Viper_Strike_Effect, caster, EVENT_UNIT_SPELL_EFFECT ) 
        call SetTableObject(s, "co", TriggerAddCondition( trg_Viper_Strike_Effect, b ))
        call SetTableObject(s, "ac", TriggerAddAction( trg_Viper_Strike_Effect, function Trig_Viper_Strike_Effect_Actions ))
        call SetTableObject(s, "be", b)
        set b = null
        set trg_Viper_Strike_Effect = null
    else
        call SpellTargetErrorMessage( "|cffffcc00Must target walkable land.|r" )
    endif
    set caster = null
    call RemoveLocation(spot)
    set spot = null
endfunction

function Trig_Viper_Strike_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == GetAbilityId_ViperStrike()
endfunction

//======================================================================  =====
function InitTrig_Viper_Strike takes nothing returns nothing
    set gg_trg_Viper_Strike = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Viper_Strike, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Viper_Strike, Condition( function Trig_Viper_Strike_Conditions ) )
    call TriggerAddAction( gg_trg_Viper_Strike, function Trig_Viper_Strike_Actions )
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top