# Game over screen problem in a game

**URL:** <https://discourse.processing.org/t/game-over-screen-problem-in-a-game/39903>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 27, 2022, 6:49pm UTC](https://discourse.processing.org/t/game-over-screen-problem-in-a-game/39903 "2022-11-27T18:49:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![processinglearner](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@processinglearner](https://discourse.processing.org/u/processinglearner)\
**Post date:** [November 27, 2022, 6:49pm UTC](https://discourse.processing.org/t/game-over-screen-problem-in-a-game/39903/1 "2022-11-27T18:49:47Z")

</div>

hi! I made one game with loop.And there is game screen in the end.But this screen should be active for 5 seconds in the loop.My code is like this:

```auto
void draw()
{
...
if( frameCount / 60 == 3 )
  {
    fill(255, 0, 255);
    textSize(100);
    text("GAME OVER!", 80, 500);
    playGame = false;

if( playGame == false && frameCount > 180 )//wait 5 seconds
  {
    playGame = true;
  }
....

```

there is something wrong but i don’t know why this code isn’t working.Can you help me please?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 27, 2022, 6:59pm UTC](https://discourse.processing.org/t/game-over-screen-problem-in-a-game/39903/2 "2022-11-27T18:59:45Z")

</div>

separate where you set playGame and where you display the message

```auto

boolean playGame=true; 
int gameTimer=0, gameOverTimer=0; 

// in draw()

// step 1: set game over?
if (playGame) {
  if (millis() - gameTimer > 30000) { // 30 seconds 
    playGame = false;
    gameOverTimer = millis();
  }
}

// step 2: display message 
if (playGame == false) {
  fill(255, 0, 255);
  textSize(100);
  text("GAME OVER!", 80, 500);

  if (millis() - gameOverTimer > 5000) {
    // wait 5 seconds
    // go back: 
    playGame = true;
    gameTimer = millis();
  }
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 27, 2022, 7:00pm UTC](https://discourse.processing.org/t/game-over-screen-problem-in-a-game/39903/3 "2022-11-27T19:00:00Z")

</div>

Hello,

Try it with two separate `if()` blocks.  
Use `println()` statements to monitor flow of code.

```auto
void draw()
  {
  if( )
    {
    //...
    println("Game Over!");
    println(playGame);
    }
    
  if( )//wait 5 seconds
    {
    //...
    println(playGame);
    noLoop();
    }  
  }

```

`:)`

---

<div class="post-metadata">

**Author:** ![processinglearner](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@processinglearner](https://discourse.processing.org/u/processinglearner)\
**Post date:** [November 27, 2022, 7:02pm UTC](https://discourse.processing.org/t/game-over-screen-problem-in-a-game/39903/4 "2022-11-27T19:02:53Z")

</div>

thank you!!! I will try to add it to the game 👍

---

<div class="post-metadata">

**Author:** ![processinglearner](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@processinglearner](https://discourse.processing.org/u/processinglearner)\
**Post date:** [November 27, 2022, 7:03pm UTC](https://discourse.processing.org/t/game-over-screen-problem-in-a-game/39903/5 "2022-11-27T19:03:52Z")

</div>

thank you too much!!! 😊
