Log In  


Im trying to make an inverse or reverse for this function to countdown. How do I make a countdown timer?

function _update()
print(time())
if time() >= 10 then
time=0
end
end



-- at the start there is no countdown
countdown = nil

-- call this function to start the countdown
function start_countdown()
 countdown = 10
end

function _update()
 if countdown ~= nil then
  countdown = countdown - 1
  if countdown == 0 then
   countdown = nil -- stop the countdown
   -- do something here
  end
 end
end

dredds solution is good, but you might want your countdown to go in seconds, where as theirs counts down 1 per frame (30 per second). This version counts down in seconds. Not sure why you'd want to revert to nil, so I just made it count to zero then stop there.

countdown=0

function start_countdown()
  countdown = 10
end

function _update()
  countdown=max(0,countdown-1/30)
  print(ceil(countdown))
end


[Please log in to post a comment]