• 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.

[vJASS] Some timer and trigger questions

Status
Not open for further replies.
Level 2
Joined
Sep 25, 2013
Messages
6
Hi Hivers, few questions here,

JASS:
scope blah initializer Init
    
    globals
        private timer t
    endglobals
    
    private function timeOut takes nothing returns nothing
        call BJDebugMsg("blah blah blah")
        call DestroyTimer(t)
    endfunction
    
    private function cond takes nothing returns boolean
        if GetSpellAbilityId() == 'A000' then
            set t = CreateTimer()
            call TimerStart(t, 3., false, function timeOut)
        endif
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( t, function cond )
    endfunction


endscope

1.) From the code above, does the Timer leaks? if it's, how can i remove the leaks?

2.) Can i use a local Timer instead of declaring a global timer? does it leaks?

3.) Does this use of Timer fully MUI? it only run two times when three unit cast. :vw_wtf:

4.) From the code above, should i nullify or destroy the local trigger to prevent leaks?

5.) Why people use local trigger instead of gg_trg_triggername?

6.) Does TriggerAddCondition better then TriggerAddAction? why people use condition function as action instead of adding a boolean expression in it?
 
If you destroy a timer, also null the variable. But you don't even create a timer here, you only declare it. (CreateTimer() is missing)

Also here it's nap that you use "t" for timer variable and also "t" for trigger variable.

And no, this is not MUI. Only one timer can run per instance. Use local timers and call the function when timer expires. And it doesn't leak if you always null local timer and also destroy it after expired.

No need to destroy the local trigger, because you probably will need it later I think?
No need to null the local trigger, because you don't destroy it.

"Why do someone use local trigger". Why not? "gg_trg_triggername" happens if you convert from GUI to jass. But in JASS you can create more trigger in one function. So no need to create a new file for each trigger.

call TriggerAddCondition( t, function cond )
-->
call TriggerAddCondition( t, Filter(function cond ))

Filter is a function which returns a boolean expression. So change your trigger function to "returns boolean" and return false in end of function. (the execution will be faster)
 
Last edited:
JASS:
scope blah initializer Init
     
     globals
         hashtable hash = InitHashtable()
     endglobals
     
     private function timeOut takes nothing returns nothing
         local timer t = GetExpiredTimer()
         local integer blub = LoadInteger(hash, GetHandleId(t), 0)
         local unit caster = LoadUnitHandle(hash, GetHandleId(t), 1)
         //... etc. Load all your data like this!
         call FlushChildHashtable(hash, GetHandleId(t))
         call BJDebugMsg("blah blah blah")
         call DestroyTimer(t)
         set t = null
         set caster = null
     endfunction
     
     private function cond takes nothing returns boolean
         local timer t = null
         if GetSpellAbilityId() == 'A000' then
             set t = CreateTimer()
             call SaveInteger(hash, GetHandleId(t), 0, GetRandomInt(0,100))
             call SaveUnitHandle(hash, GetHandleId(t), 1, GetTriggerUnit())
             //...etc. ... store all your data like this!
             call TimerStart(t, 3., false, function timeOut)
         endif
         set t = null
         return false
     endfunction
     
     private function Init takes nothing returns nothing
         local trigger t = CreateTrigger()
         call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
         call TriggerAddCondition( t, function cond )
         set t = null
     endfunction


endscope
This is the basic principle of making spells MUI by using timers and attaching data to them via hashtables.

However, you should use one single global hashtable for all timer attaching instead of having a seperate hashtable for each spell. That's why I didn't privatize it.
 
Status
Not open for further replies.
Top