- 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:
Because I use PUI to attach the struct to a unit, I access it when some event runs.
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.
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, 039;B000039;) > 0 then
set color = GetPlayerColorS(GetOwningPlayer(this.cast))
call CreateShieldEx(this.cast, mana, 60., 039;B000039;, 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.