Following up on @roaminggamer’s comment: every time you go back to the scene, you’re probably starting another timer; if you print the value after each update, I bet you’ll see the 1-2-3- sequence every time on the console; but they’re happening so fast that the on-screen text box looks like it is jumping 2-4-6- or 3-6-9-. Save the clockTimer value somewhere; if not-nil then cancel-and-restart.
My menu is a composer scene
Okay, i try to save the timer.cancel above the createQuestion() it works but the timer delays.
How? Shall i remove return true of the function?
Here’s my createQuestion() function bob.
KilikSky,
I see you added that createQuestion function to your original post. What I would like to see is ‘all’ the menu scene code and all the code for this scene where the startTimer code is.
Are you able to post the COMPLETE CODE for ‘menu scene’ and this ‘main action scene’ ???
It still appears that - the startTimer - seems to run multiple times, each time you leave scene to menu scene and return (this is based on what you stated in your original comments). There is actually a couple of ways that could be happening. The scene:create scene:show and scene:hide would be important sections to look at in both menu scene and this scene.
Maybe one of the more experienced developers can see for sure from this last bit of code you posted, what ‘exactly’ is causing the issue. But it appears we all think it is that startTimer running multiple times each time you return from menu scene. As roaming gamer noted be sure to either cancel the timer when you leave the scene or maybe just start it once.
But I would need to see the 2 scenes complete code for me to pinpoint the exact line of code where this problem is created.
I hope this helps.
Bob
Check my menu scene i already edited it…
Great. How about the complete code for the scene that handles the questions and has the startTimer function in it.
Then I can see where and how you have the variable ‘currentTime’ declared, and if for some reason if you have it global, as well as what you have in that scene:show … for that scene.
You can also put a print statement inside the ‘startTimer’ function and then check your console output to see if indeed that is called more then once when you return to that scene from menu scene.
Still guessing, but it is also possible that you have the ‘currentTime’ as global and it is not getting reset when you return to this scene… There also could be somewhere in this scene where you are incrementing ‘currentTime’ in some manner besides just in the ‘doCountUp’ function,.
But, I do not see in your sample code, enough code, to know about that variable.
my startTimer is not called once when i return to the menu scene… my currentTime is global i save the timer on GameOver scene. See my code at the top the 1st one its a complete code for gameplay scene…
I have not had a lot of time today to look at this, but I have a couple of questions :
- what do you mean by this … what do you mean by ‘default’ and what ‘previous one’?
BTW that is the default startTimer than the previous one
- I see in your game scene in the scene:hide you cancel several timers. That is good, but why are you not cancelling the ‘clockTimer’ also?
I ask question #2 because it appears in your game scene you only call(exit to) gameOver scene.
-
is gameOver scene actually Does gameOver then call menuScene?
-
In any case, if game is over, I am not sure why you would not cancel ‘clockTimer’ when the scene hides. So last question is, can you search all the files/modules of your code for the variable currentTime (that you have as global) and find everywhere you ‘increment’ ‘currentTime’ value?
-
You say you save the timer on GameOver scene … why? and which timer are you taking about?
-
In the statement below, did you mean ‘when you return ‘FROM’ menuScene’? because the startTimer function I was asking about is in the mainScene or game scene… so I am confused by this statement :
my startTimer is not called once when i return to the menu scene
no. 3 was correct after the gameplay it will go to gameOver and has a home button for menu scene. I have a currentTime variable only on my gameOver in which i set it to text variable. CurrentTime is where i save my time on text in game Over. ill, put my gameOver Scene
Could you give me some answer to questions 1 & 2 from my last post.
And to be clear, the only scenes (or modules) that the ‘global’ ‘currentTime’ variable is in are the mainScene and the gameOverScene, correct?
I am assuming that it is the ‘countUpText’ that you are reporting is the value that you are having the issue with… I mean that is the variable that is showing the 1,2,3,4 then 2,4,6,8 then 3,6,9,12 you mention in your original post, is that correct?
you might look at these 2 lines of code: (in gameOver scene)
Look at lines 133 and 137. Do you mean to assign ‘currentScore’ on both of those? I would ‘guess’ maybe
on line 137 you would be wanting to assign ‘currentTime’ not ‘currentScore’. I am just guessing.
I am not saying this is the cause of the problem, just something I noticed.