• 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] My Timer don't fire, why?

Status
Not open for further replies.
Level 3
Joined
Apr 21, 2012
Messages
33
JASS:
scope FrostStrom initializer init

    globals
        private constant real i = 1.0 //Interval
        private timer t
        private real x
        private real y
    endglobals
    
    function execute takes nothing returns nothing
        call BJDebugMsg("Tick!")
    endfunction

    private function condition takes nothing returns boolean
        return GetSpellAbilityId() == 'A000'
    endfunction
    
    private function action takes nothing returns nothing
        local location loc = GetSpellTargetLoc()
        local unit u = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h001', loc, 180.0)
        local integer i = 0
        set x = GetLocationX(loc)
        set y = GetLocationY(loc)
        call BJDebugMsg(R2S(x))
        call BJDebugMsg(R2S(y))
        call TimerStart(t, i, true, function execute)
        
        
        call KillUnit(u)
        call BJDebugMsg("Unit Kiled")
        set u = null
        set loc = null
        
    endfunction
    
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function condition))
        call TriggerAddAction(t, function action)
    endfunction
        
endscope

The above code is what I wrote for testing purpose. But then when I test I find that my timer never fire.(The debug message in the execute function never run) As you can see I had put some debug msg so I can figure it out that everything run just fine until it reach the timer one. So I come here to seek for some help. Can you find out that what's wrong? Thanks!
 
Level 7
Joined
Apr 5, 2011
Messages
245
Corrected.
JASS:
scope FrostStrom initializer init

    globals
        private constant real i = 1.0
        private timer t
        private real x
        private real y
    endglobals
    
    function execute takes nothing returns nothing
        call BJDebugMsg("Tick!")
    endfunction

    private function condition takes nothing returns boolean
        return GetSpellAbilityId() == 'AHtc'
    endfunction
    
    private function action takes nothing returns nothing
        local location loc = GetSpellTargetLoc()
        local unit u = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h001', loc, 180.0)
        local integer j = 0 //This one was called the same as global constant real i, 0.0 interval was used instead.
        //Don't name local variables as globals.
        set x = GetLocationX(loc)
        set y = GetLocationY(loc)
        call BJDebugMsg(R2S(x))
        call BJDebugMsg(R2S(y))
        call TimerStart(t, i, true, function execute)
        call KillUnit(u)
        call BJDebugMsg("Unit Kiled")
        set u = null
        set loc = null
    endfunction
    
    private function init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        set t = CreateTimer() //You forgot to create a timer.
        call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(trig, Condition(function condition))
        call TriggerAddAction(trig, function action)
    endfunction
        
endscope
2 mistakes.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
he don't need to create in 'init' and MUST NOT create there:D, cuz the timer will be created even if the Condition fails...so it leaks
It doesn't leak, since a reference to it is preserved. It's a waste of memory, but a memory leak specifically involves the object not being able to be referenced yet still taking up memory (an important distinction).

That said, creating the occasional extra handle is not a big deal. The issue with most actual leaks is that if they occur very frequently (usually in 0.01s repeating timers or similar situations) you can rapidly generate silly numbers of useless handles. You'd have to try very hard to explicitly create enough individual handles to cause issues without any sort of looping/recursive/otherwise complicating mechanism.
 
Status
Not open for further replies.
Top