Unexpected behavior of repeating frame timers

Is it intended that a repeating frame timer with a duration of x runs for x + 1 frames before starting over?

I create a simple frame timer that prints the frame for 4 frames and repeats.

t = playdate.frameTimer.new(4)
t.repeats = true
t.updateCallback = function (timer)
  print(timer.frame)
end

This prints 1 2 3 4 0 1 2 3 4 0 1 2 3 4 and so on which means that it runs for x + 1 frames before repeating again.

I understand that this comes from the fact that a non-repeating timer starts at 0 when set up and then updates for x frames but when repeating I expected the last step in one repetition and the first step in the next to coincide.
I’m not asking to change it but if it’s intended, it would be good to mentioned it in the documentation because it took me a bit to figure out what’s going on. :slight_smile:

1 Like

I believe this is also the case for repeating standard timers. To get 1 second I do playdate.timer.new(999, callback).

It’s confusing because although it makes sense to count timers from zero it conflicts with Lua being 1-based.