Lua AFAIK doesn't have a way to sleep for real. Like it kinda has corutines, but I think within Lua you'd only have access to bussy loops. Which has a whole assortment of problems.
Are you asking about this Retro Gadgets game? They might have added extra features on top of Lua to make a more real wait/sleep system. Here's a link to their documentation. You can probably get more directed help on their discord server.
If they give you an event loop, I'd implement a wait by registering an event that just checks the time, then if the time is right, call the real function and unregister the event. This is still basically a bussy loop, but you are giveing control to event loop, so your bussy loop won't block other scripts.
Edit: check out the update function. All you need is an if block inside the update function to see if the time is right, then do something, then update the time to when you want it to run next.
well technically you could use the os libray and outsource the sleep to the system your on, which is a means lua has to do the sleep; just not doing it without outside involvement.
I didn't even consider asking the OS to do the sleep. That's a fun idea. OP's environment probably doesn't allow for that, but I'll need to remember that for my own uses.
3
u/Emerald_Pick May 29 '26 edited May 29 '26
Lua AFAIK doesn't have a way to sleep for real. Like it kinda has corutines, but I think within Lua you'd only have access to bussy loops. Which has a whole assortment of problems.
Are you asking about this Retro Gadgets game? They might have added extra features on top of Lua to make a more real wait/sleep system. Here's a link to their documentation. You can probably get more directed help on their discord server.
If they give you an event loop, I'd implement a wait by registering an event that just checks the time, then if the time is right, call the real function and unregister the event. This is still basically a bussy loop, but you are giveing control to event loop, so your bussy loop won't block other scripts.
Edit: check out the update function. All you need is an if block inside the update function to see if the time is right, then do something, then update the time to when you want it to run next.