# About Restarting

**URL:** <https://discourse.processing.org/t/about-restarting/22557>\
**Category:** Coding Questions\
**Created:** [July 11, 2020, 8:25pm UTC](https://discourse.processing.org/t/about-restarting/22557 "2020-07-11T20:25:28Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [July 14, 2020, 9:42pm UTC](https://discourse.processing.org/t/about-restarting/22557/3 "2020-07-14T21:42:40Z")

</div>

You need to manage the reset, as @Chrisir says. If you create a bunch of global variables objects and then run setup() again their values will persist – unless you manually reset them.

If your sketch relies on frameCount or millis(), you will also need to track them over restarts.

frameCount can be manually reset if you need to – if it is set to -1, then it will advance to zero and automatically re-run setup(). This is one easy way of restarting a sketch.

Note however that millis() will still measure from the time the sketch launched – not from restart – so if you want to measure the time since restart, you need a custom millis().

### reset specific things with a reset function

```auto
int count = 0;
void setup() {
   size(200,200);
   reset();
}
void reset() {
  count = 0;
}
void draw() {
  background(128);
  text(count, width/2, height/2);
  count++;
}
void keyReleased() {
  reset();
}

```

### reset by rerunning setup() with frameCount= -1

```auto
int count = 0;
void settings() {
  size(200,200);
}
void setup() {
   count = 0;
}
void draw() {
  background(128);
  text(count, width/2, height/2);
  count++;
}
void keyReleased() {
  frameCount = -1; // reset
}

```

### reset plus keep a per-reset timer

```auto
int count = 0;
int resetStart = 0;
void setup() {
   size(200,200);
   reset();
}
void reset() {
  count = 0;
  resetStart = millis();
}
void draw() {
  background(128);
  text(count, width/2, height/2);
  text(timer(), width/2, 12 + height/2);
  text(millis(), width/2, 24 + height/2);
  count++;
}
void keyReleased() {
  reset();
}
int timer() {
  return millis() - resetStart;
}

```

---

_[View the full topic](https://discourse.processing.org/t/about-restarting/22557)._
