Jump to content

Can't break out of end loop


iamnotanumber10
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...