# How to put a "replay" button on my game?

**URL:** <https://discourse.processing.org/t/how-to-put-a-replay-button-on-my-game/11676>\
**Category:** Libraries\
**Tags:** homework\
**Created:** [May 29, 2019, 12:38pm UTC](https://discourse.processing.org/t/how-to-put-a-replay-button-on-my-game/11676 "2019-05-29T12:38:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sachy](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@sachy](https://discourse.processing.org/u/sachy)\
**Post date:** [May 29, 2019, 12:38pm UTC](https://discourse.processing.org/t/how-to-put-a-replay-button-on-my-game/11676/1 "2019-05-29T12:38:03Z")

</div>

Hello everyone, i made a small game with processing (coded in JAVA) for my exams. But i still don’t know how to replay the game when it’s lost. I already searched on the net and tried few things but it doesn’t work. So I wonder, could you help me ?

That’s my code : [https://pastebin.com/hUJqAYKa](https://pastebin.com/hUJqAYKa)

Thank’s if you could help me.  
I don’t have any idea, i’m pretty bad at coding, our teacher made most of this code.

---

<div class="post-metadata">

**Author:** ![colin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/colin/32/230_2.png) [@colin](https://discourse.processing.org/u/colin)\
**Post date:** [May 29, 2019, 12:52pm UTC](https://discourse.processing.org/t/how-to-put-a-replay-button-on-my-game/11676/2 "2019-05-29T12:52:48Z")

</div>

The idea will be to create a function that reset all the variables who change during your game. Like this :

```auto
void resetGame(){
  point = 0;
  // and so on
}

```

And then call it when you want, for example when the player press space :

```auto
void keyPressed() {
  
  if (keyCode==32) resetGame();
  
}

```

Have fun finding which variable have to be initialized 🙂

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [June 1, 2019, 5:41pm UTC](https://discourse.processing.org/t/how-to-put-a-replay-button-on-my-game/11676/3 "2019-06-01T17:41:59Z")

</div>

If you are planning on “setting up” state in a sketch more than once, you can also make your resetGame code that you call from setup – so everything that you want to do on any setup, including the very first one – not just resets.

```auto
int score;
void setup(){
  size(200,200);
  setupGame();
}
void draw(){
}
void keyReleased(){
  if(key=' '){
    setupGame();
  }
}
void setupGame(){
  score=0;
}

```
