# 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:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SouSageYa](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sousageya/32/9819_2.png) [@SouSageYa](https://discourse.processing.org/u/SouSageYa)\
**Post date:** [July 11, 2020, 8:25pm UTC](https://discourse.processing.org/t/about-restarting/22557/1 "2020-07-11T20:25:28Z")

</div>

Can I write a Reset code for my sketch. Like the Stop and Run method

---

<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:** [July 11, 2020, 10:29pm UTC](https://discourse.processing.org/t/about-restarting/22557/2 "2020-07-11T22:29:30Z")

</div>

No, you have to do it manually

Move everything from setup except size into a new function and then call it from setup and Also when you want to restart

---

<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;
}

```
