# Problems using getItem and storeItem - any suggestions

**URL:** <https://discourse.processing.org/t/problems-using-getitem-and-storeitem-any-suggestions/20108>\
**Category:** Coding Questions\
**Created:** [April 24, 2020, 8:19pm UTC](https://discourse.processing.org/t/problems-using-getitem-and-storeitem-any-suggestions/20108 "2020-04-24T20:19:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RetProf](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@RetProf](https://discourse.processing.org/u/RetProf)\
**Post date:** [April 24, 2020, 8:19pm UTC](https://discourse.processing.org/t/problems-using-getitem-and-storeitem-any-suggestions/20108/1 "2020-04-24T20:19:44Z")

</div>

I am attempting to develop a sketch that will collect information and store it for use in subsequent reloads of the sketch. Given the information related to the “storeInfo” and “getInfo” operations I was under the impression that the following sketch.js would accomplish that and the “counter” would accumulate with each reload. It doesn’t. I have run it with and without the use of a localhost and with Chrome and Safari on a Mac. This is not much more than a small expansion of the Examples provided on the p5.js website.

It never appears to “find” the value for “myCounterOld” on a reload of the sketch - Isn’t that what it is supposed to be able to do? Any ideas"

```auto
// Click the mouse to change the displayed counter
 // Once you have changed the counter
 // it is supposed to stay changed even when you
 // reload the page - but it doesn't.

let myCounterOld;
let myCounter;

function setup() {
   createCanvas(400, 300);
   background(122);
   getItem('myCounterOld');
   if (myCounterOld === undefined) {myCounter =0; myCounterOld=0;}
   else {myCounter = myCounterOld;}
 }

function draw() {
   rectMode(CENTER); fill(222); rect(width/2, height/2, .9*width, .9*height);
   textAlign(CENTER); textSize(16); fill(0); text(myCounter, width/2, height/2);
   textAlign(CENTER); textSize(16); fill(0); text(myCounterOld, width/2, 3*height/4);   
 }
 //If you press the mouse, the counter increments.
function mousePressed() {
   myCounter = myCounter + 1;
   myCounterOld=myCounter;
   storeItem('myCounterOld', myCounterOld);
 }

```

---

<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:** [April 24, 2020, 8:36pm UTC](https://discourse.processing.org/t/problems-using-getitem-and-storeitem-any-suggestions/20108/2 "2020-04-24T20:36:11Z")

</div>

> [@RetProf](#):
>
> `getItem('myCounterOld');`

`myCounterOld = getItem('myCounterOld');`

> **[reference | p5.js](https://p5js.org/reference/#/p5/getItem)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

> <https://gist.github.com/GoSubRoutine/dabbc9371441720a07bd5de513a6b890>

---

<div class="post-metadata">

**Author:** ![RetProf](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@RetProf](https://discourse.processing.org/u/RetProf)\
**Post date:** [April 24, 2020, 8:54pm UTC](https://discourse.processing.org/t/problems-using-getitem-and-storeitem-any-suggestions/20108/3 "2020-04-24T20:54:27Z")

</div>

Got it. I thought I had tried that but obviously I had not done something correctly.  
That works as advertised. Once again the Forum saves me!  
Thank you for this amazingly fast solution.  
Cheers and stay safe where ever you are!
