Way to set action after all time delayed functions have finished?

For a part of the game I’m trying to make, there’s a phase where it’s some text shows up on the screen for a few seconds each time. So far I did it with a timer.performWithDelay.

But I also want another text object to show up after all of the items have been cycled through. However, if I just put in some code after the timer statement, it will immediately show up while the queued items are still running.

timer.performWithDelay( 1000, showNext, 5 )

– I want to wait until all the time-delayed calls are done somehow

transition.to( endText, { time=300, x = centerX, y = centerY } )

Is there a good way to make code after the performWithDelay run after all the pending showNexts have finished? I know you could use another performWithDelay statement after it, but wouldn’t that force every additional statement after it to have time delays?

I’m still not understanding exactly what you want. Can you post some sample code and explain what you what a little more?

–SonicX278

The idea is kind of like having the player watch a slideshow and then ask them to do stuff with what they saw.

To do that, I have a function called showNext which updates the text display object to the next item in the list, hence the timer.performWithDelay( 1000, showNext, 5 )

So what I have so far would be something like:

Item1 (wait 1 sec) => Item2 (wait) => item3 (wait)

           apple          =>     cherry     =>       cow

What I want to do next is after ‘cow’ has finished its second on screen, have another text object pop up that would ask something like ‘How many red objects were in the items you just saw?’

But I can’t figure out how to have that final question pop up after the ‘cow’ has finished its second on screen. If I just had a transition.to after the performWithDelay line, the question would show up before ‘cow’ even comes up on screen.

I’m hoping there’s a way to do it without another performWithDelay, because wouldn’t that force anything, text or not, that comes up after ‘cow’ to be on a delay?

I hope that’s a little clearer, sorry about that!

There are a couple ways to do it, given what you’ve written.

Use the timer count:

local function showNext (event) -- normal stuff if event.count == 5 then -- 5th item? transition.to( endText, { time=300, x = centerX, y = centerY } ) end end

Alternatively, delay the transition:

transition.to( endText, { delay = 5000, time=300, x = centerX, y = centerY } )

I’m still not understanding exactly what you want. Can you post some sample code and explain what you what a little more?

–SonicX278

The idea is kind of like having the player watch a slideshow and then ask them to do stuff with what they saw.

To do that, I have a function called showNext which updates the text display object to the next item in the list, hence the timer.performWithDelay( 1000, showNext, 5 )

So what I have so far would be something like:

Item1 (wait 1 sec) => Item2 (wait) => item3 (wait)

           apple          =>     cherry     =>       cow

What I want to do next is after ‘cow’ has finished its second on screen, have another text object pop up that would ask something like ‘How many red objects were in the items you just saw?’

But I can’t figure out how to have that final question pop up after the ‘cow’ has finished its second on screen. If I just had a transition.to after the performWithDelay line, the question would show up before ‘cow’ even comes up on screen.

I’m hoping there’s a way to do it without another performWithDelay, because wouldn’t that force anything, text or not, that comes up after ‘cow’ to be on a delay?

I hope that’s a little clearer, sorry about that!

There are a couple ways to do it, given what you’ve written.

Use the timer count:

local function showNext (event) -- normal stuff if event.count == 5 then -- 5th item? transition.to( endText, { time=300, x = centerX, y = centerY } ) end end

Alternatively, delay the transition:

transition.to( endText, { delay = 5000, time=300, x = centerX, y = centerY } )