How to wait a certain amount of time?

Hello,

I’m really new with LUA, but I’m trying to figure out how to wait 3 seconds in the script before the next action takes place? I’ve putting this before the next action which I want to wait:

function afterTimer()
print(“Timer is done!”)
end
 
timer.performWithDelay(3000, afterTimer, 1)

But it just skips it and goes to the next action immediately. Does anyone know how to make it wait properly?

Thank you!

Corona SDK is an event driven system.  There are many things that happen asynchronously… that is you make the call and instead of pausing while it waits, it goes on and does the next thing in the code.  When the event happens, in this case your timer expires and your afterTimer() function gets called, then you have to handle the event there.

There isn’t a concept of stop and wait for a period of time.  So if you  have this:

function afterTimer()     print("Timer is done!") end   timer.performWithDelay(3000, afterTimer, 1) print("Now do something else")

The “Now do something else” will always print immediately and 3 seconds later “Timer is done!” will print.  What you are really wanting is:

function afterTimer()     print("Timer is done!")     print("Now do something else") end   timer.performWithDelay(3000, afterTimer, 1)  

Corona SDK is an event driven system.  There are many things that happen asynchronously… that is you make the call and instead of pausing while it waits, it goes on and does the next thing in the code.  When the event happens, in this case your timer expires and your afterTimer() function gets called, then you have to handle the event there.

There isn’t a concept of stop and wait for a period of time.  So if you  have this:

function afterTimer()     print("Timer is done!") end   timer.performWithDelay(3000, afterTimer, 1) print("Now do something else")

The “Now do something else” will always print immediately and 3 seconds later “Timer is done!” will print.  What you are really wanting is:

function afterTimer()     print("Timer is done!")     print("Now do something else") end   timer.performWithDelay(3000, afterTimer, 1)