Trigger doesn't work when I remove leak

Moon_Raven

New Member
Reaction score
8
Hello, I started to work with JASS recently, and I am still a big newbie to it. So, I have a trigger like this that works perfectly:
JASS:
function TextActions takes nothing returns nothing
call Msg("Hello",0)
endfunction

function InitTrig_Text takes nothing returns nothing
local trigger MyTrigger = CreateTrigger()
call TriggerRegisterPlayerEventEndCinematic(MyTrigger,Player(0))
call TriggerAddAction(MyTrigger,function TextActions)
endfunction

But when I add the "call DestroyTrigger(MyTrigger)" code for destroying the leak, it doesn't work:
JASS:
function TextActions takes nothing returns nothing
call Msg("Hello",0)
endfunction

function InitTrig_Text takes nothing returns nothing
local trigger MyTrigger = CreateTrigger()
call TriggerRegisterPlayerEventEndCinematic(MyTrigger,Player(0))
call TriggerAddAction(MyTrigger,function TextActions)
call DestroyTrigger(MyTrigger)
endfunction

Why doesn't it work now? Did I fix it wrong? Or the trigger doesn't leak?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
U put it at wrong place, it should like this :

JASS:

function TextActions takes nothing returns nothing
call Msg("Hello",0)
call DestroyTrigger(GetTriggeringTrigger())
endfunction

function InitTrig_Text takes nothing returns nothing
local trigger MyTrigger = CreateTrigger()
call TriggerRegisterPlayerEventEndCinematic(MyTrigger,Player(0))
call TriggerAddAction(MyTrigger,function TextActions)
set MyTrigger = null
endfunction



If u put like this, t
JASS:

function InitTrig_Text takes nothing returns nothing
local trigger MyTrigger = CreateTrigger()
call TriggerRegisterPlayerEventEndCinematic(MyTrigger,Player(0))
call TriggerAddAction(MyTrigger,function TextActions)
call DestroyTrigger(MyTrigger)
endfunction


The trigger will be destroyed instantly as it created and it wont work.
Hope i can help u.:)
 

Moon_Raven

New Member
Reaction score
8

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216

Moon_Raven

New Member
Reaction score
8
I know how to create a function Msg because somehow it is easier for me to just write Msg("text",playernumber).Don't know why...And yeah,
JASS:
set MyTrigger = null
was just what I was looking for, that cleans the leak. Bah, I knew it was something like that... Thanks a lot! +rep
And one last thing, so if I didn't put set MyTrigger = null and pressed escape 10000000 times in the game, the map would eventualy lag?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Actually would u press so many times of ESC???!!!!! Minor memory leaks do not lag the game. :) I had an experience tat I forgot to remove leak, and it leaks every .035 times for 2 seconds. (This is a spell) When i cast second times, it start lag, but not laggy. When i cast it third time, it start super lag. Luckily i have a dual-core processor, I can use another core to open task manager n close warcraft 3. :D:D:D
 

saw792

Is known to say things. That is all.
Reaction score
280
Wow kingking, stop talking crap. Jeez.

JASS:
function TextActions takes nothing returns nothing
call Msg("Hello",0)
endfunction

function InitTrig_Text takes nothing returns nothing
local trigger MyTrigger = CreateTrigger()
call TriggerRegisterPlayerEventEndCinematic(MyTrigger,Player(0))
call TriggerAddAction(MyTrigger,function TextActions)
endfunction


This does not leak at all. You need the trigger there. What we classify as a 'leak' is data that is stored and no longer required. If you destroy the trigger, the trigger can never execute. There is also no need to null the trigger either seeing as you don't actually intend to destroy it. Not nulling the trigger will certainly not leak, unless you destroy the trigger later (which you shouldn't do at this stage).
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
I only help him to solve problems according to his needs. I dunno actually he want to run trigger many times. My method is did for one time.

This is for the multi times,

JASS:
function TextActions takes nothing returns nothing
call Msg("Hello",0)
endfunction

function InitTrig_Text takes nothing returns nothing
local trigger MyTrigger = CreateTrigger()
call TriggerRegisterPlayerEventEndCinematic(MyTrigger,Player(0))
call TriggerAddAction(MyTrigger,function TextActions)
set MyTrigger = null
endfunction


This is better then original 1 becauz it remove 1 leak at least. I had tested the script this time, it should work now for multiple times.
 

saw792

Is known to say things. That is all.
Reaction score
280
He still shouldn't be using DestroyTrigger(GetTriggeringTrigger()), whether or not it is supposed to run once. Seeing as he has been following Vexorian's tutorial (as I assume from the Msg function) I doubt he needs to destroy or disable the trigger at all, seeing as it doesn't leak.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top