How to Store Data Inside the Internal Storage

I am Developing a offline Game.
I want to store data, create by the user, inside the internal storage of there phone.
Anyone can help me for how to do this please.
:slight_smile:

1 Like

Hi. You can make use of ‘stored’ variables. This saves whatever value you assign to it on the device. A stored variable retains the data on the device for as long as the app is installed on the Phone. Have a look at the documentation as well: https://docs.thunkable.com/variables

4 Likes

If you’re only storing a few pieces of information then @dmndeklerkeb’s answer is perfect.

If you are looking to store a lot of data that has similar layouts you could look at Local DB. It’s just a spreadsheet but it’s stored locally.

5 Likes

You are definitely correct @eoinparkinson !

3 Likes

@eoinparkinson I had a doubt with LocalDB - would you mind clearing it?

Does localDB refresh itself every session?

Thanks!

1 Like

No, LocalDB should be persistent if the app is installed on your phone.

Hope that helps!

2 Likes

Thank you dmndeklerkeb and eoinparkinson for helping me to solve this problem.

dmndeklerkeb, I used “app” method in variables instead of “stored” method. i will try your solution. :slight_smile:

But I used Local DB method. But it’s not worked. only show the data that i entered in the app. user’s modifications not stored. when i close and reopen the app. the user’s data are disappeared.

may be it would happened due to not define variables as ‘stored’.

1 Like

I tried.
But i cannot assign a value for variables at the beginning when i set the variable type as “stored”. What should i do now? :thinking:

1 Like

You can assign values to a ‘stored’ variable. What I did was to store the user ID on sign in to a stored variable and then to use the values in the stored variable to populate the sign in email address and password input fields. I did this so the user does not have to enter his/her email and password each time when logging in to the app. What I did with sign up was, to clear the stored values in the stored variable to save the new successful sign up values so that the signed up user don’t have to enter his/her details when signing in.

You can therefore assign a value to a stored variable for instance when a screen starts. This will ensure the initial value is stored on the device. The stored value (Global value) is then available for use in all screens’ blocks of the app if required.

2 Likes

Ok.
I am working it on right now.
thanks for the explanation. :grinning:

2 Likes

So, if we want settings/data to stick around post updates, use localDB. If it’s not vital between versions, using the stored variable is the easier item to use?

I think this answers my question of how to retain settings between updates. I currently store settings in stored variables. I’ll be updating now!

3 Likes

@jared stored variables stay stored even through new releases. I can confirm this on Android and iOS!

3 Likes

perhaps this is a bug that Only i am experiencing

2 Likes

Maybe try replace the blocks? If that doesn’t work maybe make a post about it.

2 Likes

Because of i defined variables as “stored”, do i need to connect those variables with a local DB for initialize some values when the app starts.

Thus if some variable have zero values at the beginning, is that necessary to connect those variables with a local DB.

1 Like

No,it is not necessary. It all depends on what you want to do. You can use the Control block When Screen Starts to initialize the value when the screen starts and a button for instance to set a new stored value, or you can set the value in the app to keep score or track of a value.

Screen starts: Stored value = 0
Button (+5) clicked: Stored value = 5
Button (+5) clicked again: Stored value = 10
Exit app: Stored value = 10

If you have used the control block when Screen Starts and the app starts again, then it will set it back to 0 again. You can override this with an if statement. If the Stored value is not empty or 0, then keep it to the latest stored value, else set it back to 0. Again, it depends on what you want to do.

A stored variable value saves that value to the device without saving it in a local DB.

3 Likes

Thanks dmndeklerkeb.
It’s a nice explanation.
currently I am re-correcting my previous blocks as you explained.

2 Likes