loops with delay

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

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?

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

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?

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

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 )

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 )