How do I determine if a timer is set (but not currently executing)?

Trying to set up a rule something like

  • first press of a button, set up timer to do something in 60 minutes
  • second press, re-set timer to now + 60 minutes

In order to do this, I need to determine if a timer is set to go off in the future. It would seem that the .isRunning feature of a timer would be what I need, but it seems that .isRunning only returns true if the timer is actually executing the timer’s code block, not if it’s merely scheduled sometime in the future.

Sooooo… how do I determine if a timer is set in the future, so I can reset it? I’d rather not blindly call timer.reschedule, since if the timer isn’t set in the first place it’ll generate an error.

Thanks!

how about …

if (timer_whatever !=null {

}

That’d work for the first run through, but once the timer expires, does it revert back to null? (I.e. would that work the next day?)

Nevermind, guess timers revert back to null once they’ve gone off. Thanks!

Don’t forget to set timer_whatever = null if you cancel timer_whatever :slightly_smiling:

Good tip, thanks for the reminder!

There is timer.hasTerminated or you can make sure that the timer gets set to null after it has gone off. As others have suggested, make sure to set the variable to null wherever you happen to cancel it.