You should never, ever use a busy-wait loop (i.e. a while or for loop that just runs and does nothing). You will never ever get the same time since these loops execute as fast as they can, one CPU might finish twice as fast as another CPU. Not to show my age, but I loved playing the old, F16 flight game on the PC way back when. Then I upgraded my PC and the game became completely unplayable because they used busy-wait loops to time things.
Secondly, in particular for mobile devices, users have an expectation that when they click/tap something, the UI will be responsive. If you’re using sleep()'s and busy-wait’s that UI just won’t be responsive. It’s sort of the same concept that may struggle where they want to code a dedicated game loop, which in many cases isn’t needed because Corona is event driven. That desire to call a main() function to start things off just isn’t needed. Draw your UI and react to events that come in. Of course there are somethings you want to happen without user interaction (spawning enemies, moving objects, scrolling backgrounds) that you will use a looping concept for, but it’s still a frames per second based event loop that does that work.
So if a timer doesn’t make sense for you, you can always setup a an enterFrame event (the frame per second event generator) and use system.getTimer() to determine if a millisecond amount of time has elapsed since the last enterFrame event and have your app react accordingly.
**untested code**
local lastTimerCheck = 0 local frequency = 200 local function enterFrameListener( event ) local now = event.time if now \> (frequency + lastTimerCheck) then lastTimerCheck = now taskToDo() -- your function to execute end end Runtime:addEventListener( "enterFrame", enterFrameListener )
Rob