Playdate.timer value increases between calling :pause() and :start()

It looks like a timer’s value keeps updating even after it’s been paused? I expected it to not change after :pause() was called, and to only begin incrementing again after calling :start()

I put together a minimal repro - if you press A and check the console output you will see the value incrementing normally, but if you press A again, wait for a couple of seconds, and press A once more, you will notice the value has jumped as though the timer was never paused.

import 'CoreLibs/timer'

local timer = playdate.timer.new(12000, 1, 1000)
timer:pause()
timer.updateCallback = function ()
  print('timer update', timer.value)
end
timer.timerEndedCallback = function ()
  print('timer end', timer.value)
end

local isPlaying = false

function playdate:AButtonDown()
  if isPlaying then
    timer:pause()
    print('paused timer')
    isPlaying = false
  else
    timer:start()
    print('started timer')
    isPlaying = true
  end
end

function playdate.update()
  playdate.timer.updateTimers()
end

For now, editing CoreLibs/timer.lua so that the :start() function sets the timer’s _lastTime value back to nil seems to work:

function playdate.timer:start()
	self._lastTime = nil
	self.paused = false
end
5 Likes

Thanks for the workaround!

I’ve also reported this, a long time ago, in the days when the was an issue tracker.

Is this likely to get fixed soon?

1 Like

I've tagged Dave. Until then you can edit the lua files to add the fix yourself