• 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] Masters of JASS, which do you prefer?

Status
Not open for further replies.
Level 12
Joined
Aug 7, 2004
Messages
875
Hey guys I seem to encounter another problem and is returning local trigger fields. Well truth is it should work fine but there are many implications such as limmited amount of local trigger running in virtual memory and stuff. I'm not sure about all the implications so I ask you guys, master of JASS, whether it is better to do option A or option B.

Option A:
JASS:
function InitTrigger takes nothing returns trigger
local trigger t = CreateTrigger( )
call TriggerRegisterEvent(t, ...)
call TriggerAddAction(t, ...)
return t
endfunction

Option B:
JASS:
globals
trigger gg_trg_test
endglobals

function InitTrigger takes nothing returns nothing
set gg_trg_test = CreateTrigger( )
call TriggerRegisterEvent(gg_trg_test , ...)
call TriggerAddACtion(gg_trg_test , ...)
endfunction

Both function gets called in my InitVars function which is called in the main function in the .j file.

So whats ur opinion?
 
Level 4
Joined
Jun 8, 2004
Messages
66
They both have their uses.

Generally I only create globals for triggers if I need to be able to enable/disable at will and pretty easily. If I don't need that or I won't need to kill it off later, why bother having a variable assigned to it?

If it's part of a one-shot deal what I might do instead is have it be a local and have the action destroy triggering trigger once the action is called (spelltriggers, some dialogs, etc.). You don't even really need locals for that stuff except for holding it down while you pin events and actions to it.

If you use a lot of locals though just make sure to null out all the handles after use as possible (even though this doesn't appear to be possible when you need to return the local - I'm not sure it actually would leak then anyways).
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
I use locals so I can store more triggers in one trigger
Locals are good if you dont change them later :p
and good map makings :grin:
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
The function in which you create a local trigger leaks anyways......

Use globals, unless you need more trigger inside one, in that case the original should still be global and the rest of them should be locals.

Having local triggers has it's limitations so I don't know why the hell people replace global triggers with local ones (and then when they try to disable it, they complain that it doesn't work....)

So stick with global triggers, unless you're creating a trigger (or more of them) in a spell and then destroying them afterwards, then you need to use locals (if you want the spell to be MUI).
 
Status
Not open for further replies.
Top