Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to wait a certain amount of time?
Started by fjfod Aug 06 2014 08:51 AM

* * * * * 1 votes
1 reply to this topic
wait block pause stop
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

fjfod

[GLOBAL: userInfoPane.html]
fjfod
  • Observer

  • 1 posts
  • Corona SDK

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!



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,534 posts
  • Enterprise

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)
 



[topic_controls]
[/topic_controls]