How to make my game switch scenes once a timer I have built gets to 0 seconds left

Hello I need help getting my game to switch scenes once the timer hits 0, I know there is a super simple answer for this, I am 15 years old working on my second app for the apple app store. My first one was built with unity.

Hopefully someone can help me and sorry if this post is sloppy I am in a time crunch and trying to get it out there.

Also currently I am running an if statement:

secondsLeft is currently set to 6 seconds in code above this, the code works if I set mainTest = 6 because the if statements only check right at the beginning right when it runs all of the code. How can I get this to update/refresh or use a different kind of recurring statement ???

local mainTest = 0


if (secondsLeft == mainTest) then

composer.removeScene( “game”, false )

        composer.gotoScene( “game”, { effect = “crossFade”, time = 333 } )        

    end


Please do not make duplicate posts for the same question.

You will need to use a timer, and in the timer’s listener update secondsLeft.

Yes I already have that part its just not shown in the above code. I already have the timer created but how do I literally say: when secondsLeft == 0 load game. Because my if statement does not work for that. I need something to keep checking, sorry please give an example.

Something like this

local secondsLeft = 6 local function timerListener() secondsLeft = secondsLeft - 1 if secondsLeft == 0 then composer.gotoScene( "game", { effect = "crossFade", time = 333 } ) end end timer.performWithDelay(1000, timerListener, secondsLeft)

Thank you!!! I get it, so put the if statement inside the function.      :)

Please do not make duplicate posts for the same question.

You will need to use a timer, and in the timer’s listener update secondsLeft.

Yes I already have that part its just not shown in the above code. I already have the timer created but how do I literally say: when secondsLeft == 0 load game. Because my if statement does not work for that. I need something to keep checking, sorry please give an example.

Something like this

local secondsLeft = 6 local function timerListener() secondsLeft = secondsLeft - 1 if secondsLeft == 0 then composer.gotoScene( "game", { effect = "crossFade", time = 333 } ) end end timer.performWithDelay(1000, timerListener, secondsLeft)

Thank you!!! I get it, so put the if statement inside the function.      :)