HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Problem with TimedLoop

06-08-2009, 05:44 PM#1
Tyrande_ma3x
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:

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

Collapse 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.
06-08-2009, 07:26 PM#2
Anitarf
Quote:
Originally Posted by Tyrande_ma3x
EDIT: The destroy message is never displayed.
Then add in more debug messages throughout the function and see where they stop displaying.
06-08-2009, 08:57 PM#3
cohadar
Collapse JASS:
private struct Already
//...
if Already(Data[targ]) == 0 then 
If Already is struct what is Data?
06-08-2009, 11:25 PM#4
Vexorian
Dejavu?

Dude, your color variable is never initialized unless the unit has that shield.

Why is it people no longer use war3err to test code?
06-09-2009, 01:14 AM#5
emjlr3
some of us can't get it to work, unfortunitly
06-09-2009, 03:11 AM#6
darkwulfv
Quote:
Why is it people no longer use war3err to test code?
Because it requires a dual-installation of Wc3 with the 1.21 patch. This requires effort. People are lazy.

And like emjilr said, it sometimes just doesn't work.
06-09-2009, 03:41 PM#7
Tyrande_ma3x
> Dude, your color variable is never initialized unless the unit has that shield.
Ah, correct, it was a global variable with uninitialized data. Thanks.