# How can I restart the program with keypress

**URL:** <https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446>\
**Category:** Coding Questions\
**Created:** [November 13, 2019, 4:59am UTC](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446 "2019-11-13T04:59:57Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![Kitty](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@Kitty](https://discourse.processing.org/u/Kitty)\
**Post date:** [November 14, 2019, 1:07pm UTC](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446/21 "2019-11-14T13:07:20Z")

</div>

Got it, I’ll test it out in a couple hours

---

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [November 14, 2019, 2:10pm UTC](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446/22 "2019-11-14T14:10:14Z")

</div>

yes, but maybe the visualization is not as you want (no decimals) 😅😅

---

<div class="post-metadata">

**Author:** ![Kitty](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@Kitty](https://discourse.processing.org/u/Kitty)\
**Post date:** [November 14, 2019, 2:45pm UTC](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446/23 "2019-11-14T14:45:41Z")

</div>

It’s okay as long as the timer resets it is okay.  
Do the red fireballs spawn when the timer reset?

---

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [November 14, 2019, 2:49pm UTC](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446/24 "2019-11-14T14:49:50Z")

</div>

Ohh, yes, the fireballs spawns and have just tried once again and when I win, the win screen pop up, but then, to start a new game I couldn’t clicking enter, had to click “q”.

---

<div class="post-metadata">

**Author:** ![Kitty](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@Kitty](https://discourse.processing.org/u/Kitty)\
**Post date:** [November 14, 2019, 2:54pm UTC](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446/25 "2019-11-14T14:54:21Z")

</div>

Oh yes, that is a mistake on my part. Thank you very much for letting me know, I test it out in a bit

---

<div class="post-metadata">

**Author:** ![Kitty](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@Kitty](https://discourse.processing.org/u/Kitty)\
**Post date:** [November 14, 2019, 4:52pm UTC](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446/26 "2019-11-14T16:52:58Z")

</div>

IT WORKS. Thank you so much.

---

<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:** [November 22, 2019, 7:18pm UTC](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446/27 "2019-11-22T19:18:31Z")

</div>

One simple way of approaching restart-timing is to rerun your setup each time you restart, and maintain a global variable with the last time you restarted. This lets you compute either the total run time (millis) or the current runtime (restart-millis).

Processing always runs setup on frame 0 – so one way to rerun it (and reset frameCount at the same time) is to set the frameCount to -1.

```auto
/**
 * Restart Frame 0
 * 2019-11 Processing 3.4 
 * Press key to restart -- setup() runs again on the following frame.
 * Sketch demonstrates computing a custom millis based on last restart.
 */

int start;
color bgcolor;
int level = 0;

void setup() {
  start = millis();
  bgcolor = color(random(255), random(255), random(255));
  level = level + 1;
}

int reMillis() {
  return millis()-start;
}

void draw() {
  background(bgcolor);
  text(level, 20, 20);
  text(frameCount, 20, 40);
  text(reMillis(), 20, 60);
  text(millis(), 20, 85);
}

void keyReleased() {
  frameCount = -1;
}

```

Note that this behavior isn’t officially documented in the reference – but it has been a part of Processing for a very long time.

[Previous page](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446.md?page=1)
