Basic playdate.timer question

Hey folks, I have a super basic question (I hope) related to timers. Coding knowledge extremely limited, so I'm trying to learn as I go basically.

I have a generic countdown function that takes a duration, and displays that countdown on screen, before proceeding with the game. I've implemented it based on another thread I found here, with playdate.wait().

Here's the code:

function countdown(duration)
  local duration = duration

    gfx.drawTextAligned( "*"..duration.."*", 200, 110,
    duration = duration - 1
  until (duration < 1)

Now this is functional, but I want to have some input and draw stuff still happening while this countdown is displayed, and wait() pauses everything, so I'm trying to figure out alternative ways. I've tried using, but every attempt at getting a timer working has failed miserably in ways I'm not really understanding, so I think my very basic timer understanding is completely off. Maybe a timer isn't even the way to go here? I'm not sure.

Any advice/suggestions? Examples would be really helpful! Thank you.

timer.performAfterDelay might be more what you're describing.

Or you could use a standard timer and set timer.repeats to True so it will keep triggering every second.

Or instead of repeating a timer over and over, you could use a single standard timer and keep getting its value with timer.currentTime. Convert from ms to seconds by dividing by 1000, then subtract that progress from whatever starting number you've chosen so that the number counts down instead of up.

You can turn fractional seconds into a nice integer with math.floor().

All of those would allow your update loop to keep running, with no wait.

So I've tried to use standard timers and performAfterDelay based on the documentation, but it's kinda lacking real world examples, which made it hard (for me) to get something working based on the documentation alone. Any basic examples of timers in use in a similar kind of context would be real useful to help me get my head around the syntax and structure of them.

I'm not sure of your exact needs, but when I was getting started I would do a lot of searching of the example scripts installed with the SDK. I would just select the Examples folder and then search for some term from the SDK docs, and usually find a few useful code examples.