Timer does not count down anymore

Since the last SDK update timer is behaving oddly. In the sample code below, it used to count down from 200 to 0 but now it jumps to 210 once it reaches 190!

Using Nova with SDK 2.4.2

import "CoreLibs/object"
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/timer"

local gfx <const> = playdate.graphics

local playTimer = nil
local playTime = 200 * 1000

local function resetTimer()
	playTimer = playdate.timer.new(playTime, playTime, 0, playdate.easingFunctions.linear)
end

local function initialize()

	local backgroundImage = gfx.image.new("images/background")
	gfx.sprite.setBackgroundDrawingCallback(
		function(x, y, width, height)
			gfx.setClipRect(x, y, width, height)
			gfx.setColor(playdate.graphics.kColorWhite)
			gfx.fillRect(x, y, width, height)
			gfx.clearClipRect()
		end
	)

	resetTimer()
end

initialize()

function playdate.update()
	playdate.timer.updateTimers()
	gfx.sprite.update()
	gfx.drawText("Time: " .. math.ceil(playTimer.value/1000), 5, 5)
end

Thanks for the report, we'll look in to it!

Note that the timer functions correctly. However, the .value is not correct so displaying it doesn't work.

This is a short trace of a print(playTimer.value) for a timer set to 60000:

...
24472.0
24439.0
24405.0
24372.0
24339.0
24305.0
24272.0
24239.0
95787.79
95753.79
95721.79
...
71785.79
71752.79
71719.79
71685.79
71652.79
71618.79
71585.79
0
0
0

I think I've figured out the issue: the numbers that are passed into your timer are being specified as integers, and because they're relatively large, they are creating an integer overflow situation in the easing function.

I'm looking at the best way to fix this (maybe by converting all numbers going into the easing functions to floats?), but in the meantime, you can fix your problem by explicitly declaring your numbers as floating point. One way to do this is by changing:

local playTime = 200 * 1000

to

local playTime = 200.0 * 1000
1 Like

Thank you! I was about to raise the priority on this since it was preventing my game from running correctly.

:slight_smile:

1 Like