# Help with Stored variables!

**URL:** <https://community.thunkable.com/t/help-with-stored-variables/820024>\
**Category:** Questions about Thunkable X\
**Tags:** stored-variable\
**Created:** [September 15, 2020, 8:21pm UTC](https://community.thunkable.com/t/help-with-stored-variables/820024 "2020-09-15T20:21:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![shiv1512](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/shiv1512/32/57759_2.png) [@shiv1512](https://community.thunkable.com/u/shiv1512)\
**Post date:** [September 15, 2020, 8:21pm UTC](https://community.thunkable.com/t/help-with-stored-variables/820024/1 "2020-09-15T20:21:50Z")

</div>

Hi Thunkable Community and Support,

I’m really stuck with stored variables and it seems to be a bug. ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/5/a54c98a9b7e6af3260c0e0868e41951db4437763.png)

As per the function above the app must go to the AppTour view when the app is opened for the first time (stored variable runCount is not initialised) and the app must go to the Home view when the app is opened for 2nd time or more.

This function works perfectly well when I preview this on Thunkable Preview app (on my mobile device), however this does not work when I download the APK file. To explain this in detail consider this:

After execution of function for the first time, when I check the value of stored variable:

- On Thunkable Preview value is 1
- On APK value is 3

Please help!

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [September 16, 2020, 7:02am UTC](https://community.thunkable.com/t/help-with-stored-variables/820024/2 "2020-09-16T07:02:49Z")

</div>

Hey @shiv1512 👋

Thanks tor the question! What are I initializing your stored variable as?

And where are you calling the `setPath` function?

---

<div class="post-metadata">

**Author:** ![shiv1512](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/shiv1512/32/57759_2.png) [@shiv1512](https://community.thunkable.com/u/shiv1512)\
**Post date:** [September 16, 2020, 8:01am UTC](https://community.thunkable.com/t/help-with-stored-variables/820024/3 "2020-09-16T08:01:46Z")

</div>

Hey @domhnallohanlon,

I’m not initialising the stored variable before it’s called in this function. If I understand correctly only ‘app’ variables can be initialised, right? The setPath function is called when the app’s splash screen loads. Below is the snapshot of what I’m saying.

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/8/784a9c2176bb36fcb8569d31744076b86b6135ec.png)

---

<div class="post-metadata">

**Author:** ![Michael\_Rogulla](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@Michael\_Rogulla](https://community.thunkable.com/u/Michael_Rogulla)\
**Post date:** [September 16, 2020, 11:00am UTC](https://community.thunkable.com/t/help-with-stored-variables/820024/4 "2020-09-16T11:00:46Z")

</div>

Hi @shiv1512,

you should initialize all “stored” variables before using them for the first time. If not, their value is “null” and when you use them, a compare like “stored runCount \> 1” _may_ crash the app. I use the following blocks to initialize stored variables:  
 ![grafik](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/1/21dfc38421bd2077b860c811252a4105855d78b9.png)

Later when you use a stored variable like “UserEmail”, its value will be stored and is persistent. My block is really only for the very first usage, but necessary in APK and I think in iOS.

---

<div class="post-metadata">

**Author:** ![shiv1512](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/shiv1512/32/57759_2.png) [@shiv1512](https://community.thunkable.com/u/shiv1512)\
**Post date:** [September 16, 2020, 1:25pm UTC](https://community.thunkable.com/t/help-with-stored-variables/820024/5 "2020-09-16T13:25:41Z")

</div>

Hi @Michael_Rogulla,

Thanks for sharing this. I did as you mentioned, however, the core problem is not resolved. When I run the app for the first time:

- On Thunkable Preview value is 1.
- On APK value is 3.

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/a/9a9fcbab07eda2a2a9dae71945f7fedd0b1b084c.png)

PS: While installing the APK I’m always deleting the previously installed APK as well.

---

<div class="post-metadata">

**Author:** ![Michael\_Rogulla](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@Michael\_Rogulla](https://community.thunkable.com/u/Michael_Rogulla)\
**Post date:** [September 16, 2020, 2:16pm UTC](https://community.thunkable.com/t/help-with-stored-variables/820024/6 "2020-09-16T14:16:11Z")

</div>

Hi, I think that “stored” means, the variable is stored onto your smartphone. I don’t know if the “Preview button” sees your thunkable account as an individual device, maybe it always initializes everything. That is something only a developer can answer.

PS at which point is the value “3” displayed? I cannot see any block for output.

---

<div class="post-metadata">

**Author:** ![shiv1512](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/shiv1512/32/57759_2.png) [@shiv1512](https://community.thunkable.com/u/shiv1512)\
**Post date:** [September 16, 2020, 2:41pm UTC](https://community.thunkable.com/t/help-with-stored-variables/820024/7 "2020-09-16T14:41:35Z")

</div>

The variable is indeed stored into the device, however I read in another thread that once the app is deleted all the associated app data is also deleted.

I have a separate “debug” screen which I am using to check values for all the variables.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [September 16, 2020, 3:47pm UTC](https://community.thunkable.com/t/help-with-stored-variables/820024/8 "2020-09-16T15:47:15Z")

</div>

Can you reproduce this bug and share a link or share the link to the app you’re working on?

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 12:23pm UTC](https://community.thunkable.com/t/help-with-stored-variables/820024/9 "2024-11-08T12:23:59Z")

</div>


