Problem with TimedLoop

Reaction score
91
I recently started using TimedLoop since I thought it was a really nice snippet and was kind of useful and appealing. I didn't have any problems with it until now, where my loop kept running on and on, even thought it had to be stopped.
So, I have a struct that is created at some point of time:

JASS:

private struct Already
    unit cast
    integer ticks
    
    private method onTimedLoop takes nothing returns boolean
        call BJDebugMsg(I2S(this.ticks))
        set this.ticks = this.ticks - 1
        if this.ticks <= 0 then // This should stop it...
            set mana = GetUnitState(this.cast, UNIT_STATE_MAX_MANA)
            call SetUnitState(this.cast, UNIT_STATE_MANA, mana)
            if GetUnitAbilityLevel(this.cast, 'B000') > 0 then
                set color = GetPlayerColorS(GetOwningPlayer(this.cast))
                call CreateShieldEx(this.cast, mana, 60., 'B000', 0, 0, color, true)
            endif
            call TextTag_Unit(this.cast, "Shield Regenerated", color)
            set Data[this.cast] = 0
            call BJDebugMsg("DESTROY")
            return TimedLoop_STOP
        endif
        return TimedLoop_CONTINUE
    endmethod
    
    implement TimedLoop
    
    static method create takes unit cast returns thistype
        local thistype this = thistype.allocate()
        set this.cast = cast
        set this.ticks = R2I(10. / TimedLoop_PERIOD)
        set Data[this.cast] = integer(this)
        call this.startTimedLoop()
        return this
    endmethod
endstruct


Because I use PUI to attach the struct to a unit, I access it when some event runs.

JASS:

//==========
            if Already(Data[targ]) == 0 then 
                call Already.create(targ) // Create my struct!
                call BJDebugMsg("NEW")
            else
                call BJDebugMsg("CONTINUE")
                // Increase ticks ...
                set Already(Data[targ]).ticks = R2I(10. / TimedLoop_PERIOD)
            endif
        endif
    endif


The point is to create a new struct when there is no struct attached to that unit, or if there is it should reset the ticks. The problem is that even though the loop should be stopped with return TimedLoop_STOP it CONTINUES to run and prints negative values on my screen: 3, 2, 1, 0 (should stop), -1, -2, -3...

EDIT: The destroy message is never displayed.
 

Artificial

Without Intelligence
Reaction score
326
When you've tested, has the caster had the ability 'B000' when the spell should end? If not, then it could be caused by using the variable color uninitialized, seeing you only give it a value inside the if.

If the caster has had that ability, I think you should check GetPlayerColorS, CreateShieldEx, and TextTag_Unit for anything that'd cause the thread to stop. To me it really sounds like something is crashing the thread before you get to the destroy message, and those seem to be the only ones that could if it isn't the color thing.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top