Discord
Login
Community
DARK THEME

Timer Code Not Working

I have been trying to make a timer to make my code pause for two seconds before changing animation frames but I've run into a problem that the code only counts down 1 second before stopping. Chan anyone help me figure out what's wrong with my code? It's in the draw function so it should be updating, right?

timer = 2
  if timer > 0 then
    timer -= 1/60
  else
    if startFrame < 7 then
      startFrame += 1
      timer = 2
    else
      timer = 0
      cutscene = false
    end
end

It works fine for me.

timerUpdate = function()
  if timer > 0 then
    timer -= 1/60
  else
    if startFrame < 7 then
      startFrame += 1
      timer = 2
    else
      timer = 0
      cutscene = false
    end
  end
end

init = function()
  timer = 2
end

update = function()
  timerUpdate()
  print(timer)
end

I figured out the problem thank you!! Turns out having timer = 2 inside the actual updating system wasn't a good idea...

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community