I was experimenting with SDK version 1.9.1 (132837) on MacOS and encountered an issue where timer.timerEndedArgs overrides the arguments to timer.updateCallback, not just timer.timerEndedCallback.
I expected the updateCallback to receive the normal argument (just the timer itself) but it only gets the arguments I specified as timerEndedArguments.
The following minimal program will dump the arguments passed to the update callback to the simulator's console:
import "CoreLibs/object"
import "CoreLibs/timer"
local t = playdate.timer.new(1000, 10, 150)
t.timerEndedArgs = {1, 2, 3}
t.updateCallback = function(tm, tm2, tm3)
printTable(tm, tm2, tm3)
playdate.update = function() end
end
function playdate.update()
playdate.timer.updateTimers()
end
You'll see 1 2 3 rather than the dumped timer table.
Was about to file a bug for this, because not only this is still the case in 2.5.0, but it's not entirely clear what the intended behavior is in all cases. For playdate.timer.updateCallback the documentation states:
If the timer was created with arguments, those will be passed as arguments to the function provided. Otherwise, the timer is passed as the single argument.
which is technically true, because the arguments to playdate.timer.new() are packed into timerEndedArgs and then passed to calls to updateCallback() in timer.lua. We can call this an implementation detail, but it can cause confusion and bugs if timerEndedArgs is used concurrently for its documented purpose (providing arguments for timerEndedCallback(), which may be a different set of arguments than that for the update callback):
An array-style table of values that will be passed to the timerEndedCallback function.
What's more confusing, these arguments are not passed to the update callback in frameTimer.lua, making the two timer types behave differently and leaving us with no "official" way to pass arguments to a frame timer callback function (despite the documentation for playdate.frameTimer.updateCallback() being the same as that for time-based timers).
At the very least, I think frame timers and time-based timers should behave the same here, as the documentation hints at that being the intention, but ideally the set of arguments for updateCallback() and timerEndedCallback() would be held as separate variables.