# Startup keeps running

**URL:** https://discourse.processing.org/t/startup-keeps-running/34088
**Category:** Processing
**Created:** [December 13, 2021, 3:48am UTC](https://discourse.processing.org/t/startup-keeps-running/34088 "2021-12-13T03:48:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![hacketet](https://avatars.discourse-cdn.com/v4/letter/h/2bfe46/32.png) [@hacketet](https://discourse.processing.org/u/hacketet)
#### Post date: [December 13, 2021, 3:48am UTC](https://discourse.processing.org/t/startup-keeps-running/34088/1 "2021-12-13T03:48:06Z")

</div>

This is some code from a bigger project. This is startup code that is supposed to run only once. Howeve, it keeps resetting stuff. So I added the two lines that have the global variable ‘run’ . Now it performs as it should. It’s not a problem for me, but it isn’t what the documentation describes. Without the ‘run’ lines if I comment out the ‘draw’ sub it performs properly, otherwise it’s a mess.

```auto
void setup ()
{ fullScreen();
   rectMode(CENTER);
   background(hideColor);
   println("set_up");
   int i;
   if (run == 0) //This code runs only once
   { for (i = 0; i < 5; i++) //set all IO data to 0
     { roIN[i] = 0;
     };
     for (i = 0; i < 10; i++)
     { roOUT[i] = 0;
     };
     for (i = 0; i < 3; i++)
     { ccIN[i] = 0;
     };
     for (i = 0; i < 4; i++)
     { ccOUT[i] = 0;
     };
     for (i = 0; i < 6; i++)
     { wsIN[i] = 0;
     };
     for (i = 0; i < 11; i++)
     { wsOUT[i] = 0;
     };
     for (i = 0; i < 3; i++)
     { acIN[i] = 0;
     };
     for (i = 0; i < 3; i++)
     { acOUT[i] = 0;
     };
     for (i = 18; i < 99; i++) // draw all blocks
     { drawBlock (i);
     }
     line (865, 76, 888, 59); //draw al dark territory
     line (888, 59, 942, 59);  
     line (1354, 204, 1377, 222);
     line (1401, 222, 1629, 222);
     line (1676, 222, 1812, 222);
     drawSwitch (0, 1377, 222, 1, 1, black);
     drawSwitch (0, 1653, 222, -1, 1, black);
     line (1401, 239, 1432, 263);
     line (1455, 263, 1575, 263);
     line (1598, 263, 1621, 245);
     drawSwitch (0, 1432, 263, 1, 1, black);
     drawSwitch (0, 1598, 263, -1, 1, black);
     line (1432, 303, 1598, 303);
     line (1455, 280, 1486, 303); 
     line (1543, 303, 1574, 280);
     line (1248, 352, 1271, 370);
     line (1148, 352, 1248, 352);
     line (1487, 459, 1507, 474);
     line (1507, 474, 1570, 474);
     line (728, 835, 755, 818);
     line (755, 818, 819, 818);
     line (345, 940, 403, 940);
     line (403, 940, 426, 923);
     line (1087, 795, 1110, 777);
     line (1110, 777, 1175, 777);
     
     for (i = 0; i < 131; i++)
     { drawButton(i);
        drawSignal(i);
     }
     run++;
   };
}

void draw()
{  
}

```

---

<div class="post-metadata">

### Author: ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)
#### Post date: [December 17, 2021, 7:00pm UTC](https://discourse.processing.org/t/startup-keeps-running/34088/2 "2021-12-17T19:00:47Z")

</div>

I don’t know why setup() runs multiple times, it shouldn’t. I suspect it relates to the empty draw() function. You shouldn’t use empty draw(), I suspect it is run 60 times a second even if it’s empty. Perhaps empty draw() triggers rerun of setup().

---

<div class="post-metadata">

### Author: ![hacketet](https://avatars.discourse-cdn.com/v4/letter/h/2bfe46/32.png) [@hacketet](https://discourse.processing.org/u/hacketet)
#### Post date: [December 18, 2021, 3:35am UTC](https://discourse.processing.org/t/startup-keeps-running/34088/3 "2021-12-18T03:35:42Z")

</div>

That appears to be correct. WhenI put some empty subs in draw it ran only once. Not a big deal- I have much bigger problems to take care of.
