I have a few students working on their final project, creating a stickman survival game. They are having trouble with the score showing up too early and continually counting. What they would like to show is after the user presses play, the score will appear on the game page which begins in a bathroom. The score will continually count as the stickman stays alive. They have tried putting the code in several places but either it counts from the beginning without user input or the score will show on screen but the user cannot play the game. Any assistance would be apprecated!
There are a number of ways to accomplish this. One might be more work, but ultimately might be the best and that would be to create multiple functions that control the game play and then use the draw loop to call them. That would require refactoring the game and may take some time.
Another would be to create a variable, something like “started” and set it to false at the beginning.
Then, when the play button is pressed, the variable could be set to “true”. Then, the code that updates the score could be set inside a conditional so it would only run if “started==true”.
Give that a shot and let us know if something isn’t working out.
Also, one more thing I noticed … Near line 128 or so, there is a conditional checking to see if sign.x = 5000… make sure you use triple = (===). A single = is the assignment operator and you need == or === when comparing items inside a conditional loop.
Thank you so much! Creating the variable and setting to true worked perfectly. The boys thank you for your help!