• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Destroy triggers, when to do it?

Status
Not open for further replies.
Level 12
Joined
Apr 29, 2005
Messages
999
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?

JASS:
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
 
Level 3
Joined
Jul 12, 2005
Messages
48
Call the destroy trigger after all the actions on your actions function. And why would you set your trigger to null? Does that actually do anything?
 
Level 12
Joined
Apr 29, 2005
Messages
999
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?
 
Level 8
Joined
Nov 27, 2004
Messages
251
you destroy triggers when you dont need them.
like initialization triggers,or triggers that are created temporary for being used in a spell/system.

any object that is somehow connected to handle (descendant) should be nullified.it prevents that variable from leaking.


HANDLE
Event
player
widget
ability
force
force
group
trigger
triggercondition
triggeraction
timer
location
region
rect
boolexpr
sound
unitpool
itempool
race
alliancetype
racepreference
gamestate
playerstate
playerscore
playergameresult
unitstate
aidifficulty
eventid
unit
gamespeed
gamedifficulty
game
mapflag
mapvisibility
mapsetting
mapdensity
mapcontrol
playerslotstate
volumegroup
camerafield
camerasetup
playercolor
placement
startlocprio
raritycontrol
blendmode
texmapflags
effect
effect
weathereffect
terraindeformation
fogstate
fogmodifier
dialog
button
quest
questitem
defeatcondition
timerdialog
leaderboard
multiboard
multiboarditem
trackable
gamecache
version
item
texttag
attack
damage
weapon
sound
lightning
pathing
image
ubersplat





WIDGET
unit
destructable
item


ABILITY
buff

BOOLEXPR
filterfunc
conditionfunc

GAMESTATE
igamestate
fgamestate

EVENTID
gameevent
playerevent
playerunitevent
unitevent
limitop
widgetevent
dialogevent


now . . . the one which is writed in caps is the ancestor,the others down it are the descendants

any the descendants of handle need nullification, destruction,or removal in some cases.

JASS:
//---Destruction

call DestroyBoolExpr(b)
set b = null

//---Removal
call RemoveLocation(l)
set l = null

//---Simple nullifying.
set u = null//u ==unit
 
Level 12
Joined
Apr 29, 2005
Messages
999
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.
 
Level 8
Joined
Nov 27, 2004
Messages
251
well you destroy the trigger after that text is dislpayed.

--

I gave you those info to see which variables should be nullified.they are not the handle vars.

just for example

Handle->Wigdet->Unit

unit type variables need nullification because they come from the handle, and so for the others.
 
Level 3
Joined
Jul 12, 2005
Messages
48
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.")
call DestroyTrigger( GetTriggeringTrigger() )
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)
endfunction

Its that simple
 
Level 8
Joined
Nov 27, 2004
Messages
251
The_Prophet said:
Its that simple
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

JASS:
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
JASS:
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

doesnt leak at all!

but this might help you

http://www.wc3jass.com/viewtopic.php?t=2072
 
Level 8
Joined
Nov 27, 2004
Messages
251
esay!

when the map loads the triggers and the next trigger for load is that with the text it reads from it's initialization func.


JASS:
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.
 
Status
Not open for further replies.
Top