Another question, when do you have to destroy triggers? And when to do it? This can't be correct in my script bellow since the actions is never executed if a use those two last lines. Shouldn't the actions be executed and THEN the trigger is destroyed?
function CF_Condition takes nothing returns boolean
return GetSpellAbilityId() == 'A008'
endfunction
function Actions takes nothing returns nothing
call DisplayTimedTextToForce( GetPlayersAll(), 3.00, "Local trigger executed.")
endfunction
//===========================================================================
function InitTrig_Local_trigger takes nothing returns nothing
local trigger CT_Trigger
set CT_Trigger = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(CT_Trigger, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(CT_Trigger, Condition(function CF_Condition))
call TriggerAddAction(CT_Trigger, function
Actions)
//call DestroyTrigger(CT_Trigger)
//set CT_Trigger = null
endfunction
But I can't destroy CT_Trigger inside the actions function since CT_Trigger is a local variable that doesn't exist in that function, or can I? Can a trigger destroy it self? I have just began to experiment with using and destroying local triggers so I don't know much about it. About the null thing. All variables should be set to null when they are no longer in use, shouln't they?
Well didn't have to write down all that things since I know almost nothing about handle variables yet. What I want to know is how my example script should have been written correctly if I want the trigger to be destroyed right after the actions are executed and finnished. Any way I am very grateful that you put such efforts in your replis. Thank you.
that's what i said destroy trigger after that text is shown.
@Daminon.
no it doesnt leak. it refers to an already existant object.so doesnt leak.
call DestroyTrigger(GetTriggeringTrigger())==no leaks at all.
leaks when the game creates an object and returns it to you. exampes
GetUnitLoc() returns a location so if it is not on a variable that object cannot be removed anymore.
so
call SetPositionUnitLoc(u,PolarProjectionBJ(GetUnitLoc(u),500,GetUnitFacing(u)))
//will move the unit by 500 forward from his current
//position. but it leaks preety much!
PolarProjection Return locations that you dont remove
but if you do
local location ul = GetUnitLoc(u)
local location p = PolarProjectionBJ(ul,500,GetUnitFacing(u))
call SetUnitPositionLoc(u,p)
call RemoveLocation(l)
call RemoveLocation(p)
set l = null
set p = null
Some usefull info, some I already know. A last question about my script, why is the text never shown in the game if I use the last two commented lines?
when the map loads the triggers and the next trigger for load is that with the text it reads from it's initialization func.
function InitTrig_Local_trigger takes nothing returns nothing
local trigger CT_Trigger
set CT_Trigger = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(CT_Trigger, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(CT_Trigger, Condition(function CF_Condition))
call TriggerAddAction(CT_Trigger, function
Actions)
//call DestroyTrigger(CT_Trigger)
//set CT_Trigger = null
endfunction
--
a trigger type local. set that local to a new trigger. Register Event blah,blah Add a condition. Add action. Destroy that trigger just created set variable ct_Trigger to point nowhere in the memory.
--
those are done before the map loads. so the trigger is destroyed before map initialization.