Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

loops with delay
Started by alireza.rou13 Aug 21 2015 11:30 PM

- - - - -
3 replies to this topic
loops delay while
[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

alireza.rou13

[GLOBAL: userInfoPane.html]
alireza.rou13
  • Observer

  • 24 posts
  • Corona SDK

Hello,

I want to create a loop with delay because main.lua doesn't wait until timer end.
this is my while loop.
local status=false
while status==false do
	status=req1.whatsup()
end

 



[TOPIC: post.html]
#2

jbp1

[GLOBAL: userInfoPane.html]
jbp1
  • Contributor

  • 216 posts
  • Corona SDK

It's not entirely clear what you're asking:  do you want the whole loop (all iterations) to trigger after some delay?  or you want each iteration to be delayed from the previous iteration?  or are you trying to have one function (or thread) trigger some action in another function?



[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,544 posts
  • Enterprise

Corona SDK is an event driven system. "Busy wait" loops are not something you really want to do with Corona SDK. If you want something to happen later or at an interval, then you would use a timer.  If you're waiting on user input, you setup touch or tap event listeners that react when the screen is interacted with.

 

Rob



[TOPIC: post.html]
#4

csavalas

[GLOBAL: userInfoPane.html]
csavalas
  • Contributor

  • 109 posts
  • Corona SDK

 

Hello,

I want to create a loop with delay because main.lua doesn't wait until timer end.
this is my while loop.
local status=false
while status==false do
	status=req1.whatsup()
end

 

 

I'm a little confused, but I assume you want to perform some action over and over again with a delay in between each action. if your action is calling the function req1.whatsup(), then you would do something like this:

local whatsupTimer

local req1={}

local function req1.whatsup()

    --Here is where your functionality
    --is contained for whatsup(), then
    --add one of the next two options:

    --OPTION 1 --------------------------
    --In this option, the whatsup function
    --determines for itself if it should
    --be called again, each iteration.

    if someCondition then 

        timer.performWithDelay( 1000, req1.whatsup )

    end

    -- -----------------------------------


    --OPTION 2----------------------------
    --In this option, you set whatsupTimer to a
    --timer that can be cancelled outside of
    --whatsup() using timer.cancel( whatsupTimer ).


    whatsupTimer=timer.performWithDelay( 1000, req1.whatsup )

    -- ----------------------------------


end

Keep in mind, you don't need to start the timer within the req1.whatsup() function. If you want to start calling req1.whatsup() somewhere else indefinitely until you cancel it, disregard the above modifications to that function, and use the following wherever you like.

whatsupTimer = timer.performWithDelay( 1000, req1.whatsup, 0 )



[topic_controls]
[/topic_controls]