Actually I want the timer to reset when the user restarts
Then create a new timer. scene:show() runs twice every time the scene loads, once before the scene comes on the screen (event.phase == “will”) and once after it’s on the screen (event.phase == “did”)
So if you define your timer handle variable at the top of your scene in the main chunk:
local myTimerHandle
Then in the function scene:show()
function scene:show( event ) local sceneGroup = self.view if event.phase == "did" then -- wait until the scene is on screen myTimerHandle = timer.performWithDelay( 1000, fn\_counter, 0 ) end end
Then just before you call composer.gotoScene() to leave this scene call:
timer.cancel( myTimerHandle )
It doesn’t work
I don’t want to seem mean here, but do you realize how un-helpful " It doesn’t work" is?
What doesn’t work?
How is it not working?
What are you expecting it to do?
What are you observing happening?
Are you getting any error messages in your console.log?
While we are on the subject of how to ask for help, you have asked two questions in this thread with two blocks of code that don’t appear to go together. I don’t know if " It doesn’t work" is referring to the original question or the second smaller timer block? I have no context in how you’re trying to that timer block since it’s not part of your original code.
What I provided is probably not usable code. I have to make up example variable names. I have to assume where you’re going to use it. I have no idea how you actually implemented the code. You didn’t provide your modified code.
Please, help us help you. Take time and ask good questions. Provide the information we need to help you.
Consider this a fair warning, don’t expect responses to “It doesn’t work”.
Rob
I want the timer to count the seconds the user is in the game , and it works . When they die I want the timer to stop , that works too but I want the timer to reset when the user restarts the game because all it does is stay on the number that was previouslyg given
You are still not providing enough information.
Are you getting errors?
How about a screens shot?
Post some related code?
We want you to be successful, but you have to give us something to go on.
I’m not getting any errors , it just doesn’t work . I took the code out already because I seen that it wasn’t working for me