iamnotanumber10 Posted January 1, 2017 Share Posted January 1, 2017 Hi, I've finished my first simple game which I built with the code base of tutorials. However, when the player "dies", the restart function is meant to reset the gameOver variable, but for some reason, the game restarts with the old variable's value. This causes a death loop. The games source code here: https://www.dropbox.com/s/woyaytyih7dza02/inky_the_octopus.zip?dl=0 Here is the function I call to restart the game // called when user clicks screen area function restartGame() { gameOverText.visible = false; // hide game over text endGame = false; game.state.start('stateGame'); } At this point the game restarts, but the update loop is notified that endGame is still true and the player's death process is called. Why is this happening? Thanks. Link to comment Share on other sites More sharing options...
samme Posted January 1, 2017 Share Posted January 1, 2017 You need to reset `stopTime` as well. Link to comment Share on other sites More sharing options...
iamnotanumber10 Posted January 1, 2017 Author Share Posted January 1, 2017 Thanks, I reset stopTime here else if(stopTime){ stopTime = false; // flag to end update conditional console.log(score); checkHighScore(); } ...and it now works the second time I click the screen. That is, the death loop only runs once now. I also set the score to zero after the high-score was checked, but that also seems to be recalled when the game starts again. I've followed the conditional logic the best I can, and it shouldn't run the endGame conditional in update() as the click function does the following... function restartGame() { endGame = false; // flag for update conditional gameOverText.visible = false; // hide game over text game.state.start('stateGame'); } To and test the latest version, I've setup a live link here: http://cockroach.tk/JavaScript/inky/ So what do you think? Thanks Link to comment Share on other sites More sharing options...
samme Posted January 1, 2017 Share Posted January 1, 2017 I would do it maybe like this. I find I make fewer mistakes if I reset vars at the start (create) rather than the end. There was a playerDeath loop because the collision checks continued while the player was dead. iamnotanumber10 1 Link to comment Share on other sites More sharing options...
iamnotanumber10 Posted January 1, 2017 Author Share Posted January 1, 2017 Thanks for this, I really appreciate it. samme 1 Link to comment Share on other sites More sharing options...
Recommended Posts