Issues with stored variables not yet initialized

@ Muneer @Tatiang
Hello Thunker.
I’ve been trying for months to get a stored variable to work for me when restarting a Data Viewer List, to pick up the list where I left off. Finally, Jared has given me this video with this way of doing it in a Data Viewer Grid. And it works as explained. However, I have copied all the blocks and I have changed the names of my variables, and I saved the information while I moved between different pages of the app, that is, while I did not definitively leave the app, but when I did, the stored variable It did not work and when restarting the app, it started as usual from the beginning.
Now, after several days trying, I find myself with an especially singular behavior: So that it does not give me Null or undefined, I have added some function that I already had, specifically “Generate new question and answer”, at the end of its function " setTheScene", and it worked… until it started giving me some results that don’t even correspond to the corresponding row of the database I manage.



This is the video with the app

https://x.thunkable.com/projectPage/62701f4e416a0c001263d6ea
and this is my own app:
https://x.thunkable.com/projects/6275532298429300120083bc/e23d64c9-1312-4f4f-b479-128df03bb9ab/blocks
It should be great if you could help me with this, cause I’m really overwhelmed. Thank you

2 Likes

I don’t see where you checked for a null value in the stored variable. You have to do that.

The correct way is to say when screen opens, if stored variable = null, set stored variable to [some value]. The starting value could be true or false or “” (empty string) or really… anything. But you have to do that for stored variables to work correctly.

You can see that at the 2:17 mark in this video:

4 Likes

I thought the value I was assigning to it was 1, the first in the list, but how would it then take the value that it had previously saved?

1 Like

The stored variable will always automatically contain the value that it had when the app was backgrounded/closed/quit.

But stored variables don’t start with a value. They start as null. So you have to check for a null value as shown in the video above. Once you’ve done that, you can set the value to anything you like, such as 1.

2 Likes

Ok. TThank you… I’ll keepm trying

1 Like

Thanks for pointing this out @tatiang! I had no idea that a stored app had to be checked first. I believe this would be the root of all of my crashes. I assumed that the block would initialize it but I am now going through and making sure that all of my stored variables are checked for a null value and then given some value if they are not set.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.