# Making variables persistent?

**URL:** <https://discourse.processing.org/t/making-variables-persistent/15393>\
**Category:** Coding Questions\
**Created:** [November 11, 2019, 2:46am UTC](https://discourse.processing.org/t/making-variables-persistent/15393 "2019-11-11T02:46:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Everdro1d](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@Everdro1d](https://discourse.processing.org/u/Everdro1d)\
**Post date:** [November 11, 2019, 2:46am UTC](https://discourse.processing.org/t/making-variables-persistent/15393/1 "2019-11-11T02:46:17Z")

</div>

What I’m trying to do is make a persistent colour saver, which means that the variables that store the custom colours will need to be saved on exit and loaded on startup. I thought maybe if i could make the program write those variables to a text file on exit and then make it read and apply those on startup that would work but I have no idea how to do that. I’m really not sure what to do with it right now. If you need the code please tell me. By the way I’m using Java

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 11, 2019, 2:50am UTC](https://discourse.processing.org/t/making-variables-persistent/15393/2 "2019-11-11T02:50:37Z")

</div>

> [@Everdro1d](#):
>
> … make the program write those variables to a text file on exit and then make it read and apply those on startup…

> [@Save variable in a loop](https://discourse.processing.org/t/save-variable-in-a-loop/4654/4):
>
> /\*\* \* Load & Save Variable (v1.0.1) \* GoToLoop (2018/Oct/20) \* https://Discourse.Processing.org/t/save-variable-in-a-loop/4654/4 \*/ int a; void setup() { size(300, 200); noLoop(); fill(-1); textAlign(CENTER, CENTER); textSize(0100); final String[] aFile = loadStrings("a.txt"); if (aFile != null) a = int(aFile[0]); } void draw() { background((color) random(#000000)); text(a, width\>\>1, height\>\>1); } void mousePressed() { ++a; redraw = true; } @Override void exit()…

---

<div class="post-metadata">

**Author:** ![Everdro1d](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@Everdro1d](https://discourse.processing.org/u/Everdro1d)\
**Post date:** [November 11, 2019, 3:09am UTC](https://discourse.processing.org/t/making-variables-persistent/15393/4 "2019-11-11T03:09:47Z")

</div>

Thank you very much.
