If anyone is familiar with knife.timer on Lua, could you please look at my code and tell me what I have out of order?
I'm hoping to do two things:
- have a countdown timer that ticks down every second and
- have a timer that after six seconds begins blinking my characters for 3 more seconds before changing state.
With the following code, my countdown timer starts at 9 but gets well into the negative tens. My characters begin to blink after what feels like 4 seconds, and continue blinking for a few seconds after changing state.
I have Timer:update(dt) in main, so I'm not sure why the timing is off. And I thought the finish would not call the change state function until the characters' 16 iterations of blinking were done.
function PlayerPilotState:update(dt)
self.player.currentAnimation:update(dt)
Timer.every(1, function()
self.timer = self.timer - 1
end)
Timer.after(6, function()
Timer.every(0.2, function()
self.player.blinking = not self.player.blinking
self.player.otherPlayer.blinking = not self.player.otherPlayer.blinking
end):finish(function()
self.player:changeState('falling')
self.player.otherPlayer:changeState('falling')
end):limit(16)
end)
end
Thanks!