| 06-08-2009, 05:44 PM | #1 |
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. |
| 06-08-2009, 07:26 PM | #2 | |
Quote:
|
| 06-08-2009, 08:57 PM | #3 |
JASS:private struct Already //... if Already(Data[targ]) == 0 then |
| 06-08-2009, 11:25 PM | #4 |
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 |
some of us can't get it to work, unfortunitly |
| 06-09-2009, 03:11 AM | #6 | |
Quote:
And like emjilr said, it sometimes just doesn't work. |
| 06-09-2009, 03:41 PM | #7 |
> Dude, your color variable is never initialized unless the unit has that shield. Ah, correct, it was a global variable with uninitialized data. Thanks. |
