PerformWithDelay Does Not Resume or Restart

I have an infinite performWithDelay that I have tried to both pause and resume as well as cancel and load again. Neither work.

The timer is originally set in the “scene:show did”. When I move to a new scene I pause in the “scene:hide did”, but coming back it doesn’t resume. I tried to replace the original PWD with an “if handle is nil then set PWD else resume”. I also tired to cancel in the “scene:hide did”, then to original set PWD should load it again, but this also failed.

scene:show & phase == “did”

[lua]animateTimer = timer.performWithDelay( 1000, animate, -1 )[/lua]

or

[lua]

if ( animateTimer ~= nil ) then

    timer.resume(animateTimer)

else

    animateTimer = timer.performWithDelay( 1000, animate, -1 )

end

[/lua]

scene:hide & phase == “did”

[lua]timer.cancel(animateTimer)[/lua]

or

[lua]timer.pause(animateTimer)[/lua]

After Google & the foums have failed me, I usually get halfway through a new post before figuring it out. Since I made it to the end it must either so simple that no one else has had the problem or just that side of my understanding threshold.

Thanks ahead of time!!

Hey clarkburbidge,

I don’t know, why resuming the timer isn’t working, but regarding to what you’ve posted it’s no wonder that canceling and restarting did not work.

timer. cancel cancels the timer, but it doesn’t clear your local reference to it. So if you check for animateTimer=~ nil thsi will always be true after the first load.

To fix this you have to nil the timer after you canceled it.

timer.cancel(animateTimer) animateTimer = nil

Maybe that helps your otherwise strange problem.

I see that a problem definitely exists between the chair and keyboard with the “animateTimer = nil”. Unfortunately, that didn’t fix the issue. That was an issue with work a around that still doesn’t work. The real issue remains…

Why doesn’t my PWD resume?

Thanks for the reply and I’ll keep doing some investigation. I just built a simplest possible working example that functions correctly with the PWD pausing on goto then resuming on return, so like usual, I’ve got an error somewhere. Now to find it…

Hey clarkburbidge,

I don’t know, why resuming the timer isn’t working, but regarding to what you’ve posted it’s no wonder that canceling and restarting did not work.

timer. cancel cancels the timer, but it doesn’t clear your local reference to it. So if you check for animateTimer=~ nil thsi will always be true after the first load.

To fix this you have to nil the timer after you canceled it.

timer.cancel(animateTimer) animateTimer = nil

Maybe that helps your otherwise strange problem.

I see that a problem definitely exists between the chair and keyboard with the “animateTimer = nil”. Unfortunately, that didn’t fix the issue. That was an issue with work a around that still doesn’t work. The real issue remains…

Why doesn’t my PWD resume?

Thanks for the reply and I’ll keep doing some investigation. I just built a simplest possible working example that functions correctly with the PWD pausing on goto then resuming on return, so like usual, I’ve got an error somewhere. Now to find it…