# How to build a list using stored variables

**URL:** <https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280>\
**Category:** Questions about Thunkable X\
**Created:** [April 26, 2021, 12:13pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280 "2021-04-26T12:13:40Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwplummer1yf4f](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@rwplummer1yf4f](https://community.thunkable.com/u/rwplummer1yf4f)\
**Post date:** [April 26, 2021, 12:13pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/1 "2021-04-26T12:13:40Z")

</div>

I need to build some lists using stored variables so the list contents are remembered between uses. I can get this to work using app variables but the lists I am creating are blank the next time the app is run due to the fact I have to declare the variables as empty lists. I also need to ensure that one particular item is always first so I cant just take an app variable and say Stored variable =app variable if a new item is added. I have tried the following blocks.

 ![Capture](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/a/9a696068230ad0b96d4b152eb340d89f63558799.jpeg)  
If I leave the third list block out then the app works fine while it is open. The listviewer shows the detail entered as expected until the app is closed. When I add the third list block the app hangs when the item is submitted. I think I am close but there is clearly something I am missing. Any ideas on this. I have looked through the previous posts but perhaps my search criteria are wrong.

---

<div class="post-metadata">

**Author:** ![tony.ycy.program](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tony.ycy.program/32/100153_2.png) [@tony.ycy.program](https://community.thunkable.com/u/tony.ycy.program)\
**Post date:** [April 26, 2021, 12:18pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/2 "2021-04-26T12:18:12Z")

</div>

`Initialize device variables list1 `  
`if list1==null `  
` list1=empty list`

---

<div class="post-metadata">

**Author:** ![catsarisky](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/catsarisky/32/100661_2.png) [@catsarisky](https://community.thunkable.com/u/catsarisky)\
**Post date:** [April 26, 2021, 12:19pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/3 "2021-04-26T12:19:30Z")

</div>

I think you have an extra block in there. Try removing the circled block

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/c/5c607756e13d84fd35494de6f130200b6cfb1d6e.jpeg)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [April 26, 2021, 4:41pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/4 "2021-04-26T16:41:11Z")

</div>

Yes @catsarisky is correct as always. You are trying to reference list inside list which will result in null for your situation.

---

<div class="post-metadata">

**Author:** ![rwplummer1yf4f](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@rwplummer1yf4f](https://community.thunkable.com/u/rwplummer1yf4f)\
**Post date:** [April 26, 2021, 4:45pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/5 "2021-04-26T16:45:22Z")

</div>

I tried removing that block but it didnt change the behaviour.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/6/f6fb947d01ac2338be08bde4cbe0e9a3ef2a48a8.png) . I think this is because the stored variable is never declared as a list. I know thunkable variables can change but lists seem to need to be declared. tony-ycy might be on to something. I’ll test that next. @catsarisky thanks for taking the trouble to look.

---

<div class="post-metadata">

**Author:** ![catsarisky](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/catsarisky/32/100661_2.png) [@catsarisky](https://community.thunkable.com/u/catsarisky)\
**Post date:** [April 26, 2021, 4:50pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/6 "2021-04-26T16:50:23Z")

</div>

Oh no, Muneer. Sometimes I’m wrong. 😉

---

<div class="post-metadata">

**Author:** ![catsarisky](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/catsarisky/32/100661_2.png) [@catsarisky](https://community.thunkable.com/u/catsarisky)\
**Post date:** [April 26, 2021, 4:53pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/7 "2021-04-26T16:53:44Z")

</div>

> [@rwplummer1yf4f](#):
>
> I think this is because the stored variable is never declared as a list.

Worth trying. So you’d initialize it to an empty list. I’m wondering if your problem is that TempNickNameList isn’t getting set by the first list block, too. Text\_Nickname definitely has some text in it? (Edit: Oh, I see that you check that in the if statement enclosing this section. Right.)

I find that using some labels to look at what values are being passed around is really helpful. (For lists, I’ll use “create text from list” to make it so I can shove the list onto a label temporarily.)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [April 26, 2021, 5:02pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/8 "2021-04-26T17:02:24Z")

</div>

Thunkable has a logic issue with variables to store lists.

A variable that is “null” cannot be used to store a list. To overcome this issue first check if the variable is null and if so set it to empty list first then you can add items to it.

---

<div class="post-metadata">

**Author:** ![rwplummer1yf4f](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@rwplummer1yf4f](https://community.thunkable.com/u/rwplummer1yf4f)\
**Post date:** [April 26, 2021, 5:24pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/9 "2021-04-26T17:24:40Z")

</div>

I think I have it sorted. Not fully tested but initially it looks like this works.

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/d/6d9956f084ab1ec114c07e1819f1176baf686f0f.png)

I don’t like using null with thunkable because sometimes it returns a true null and other times it’s the word null which doesn’t evaluate to a logic test for null.  
But thanks to @tony.ycy.program , @catsarisky and @muneer for your thoughts and ideas.  
Now I just have to get the list viewer working 🙂

---

<div class="post-metadata">

**Author:** ![rwplummer1yf4f](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@rwplummer1yf4f](https://community.thunkable.com/u/rwplummer1yf4f)\
**Post date:** [April 27, 2021, 12:26pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/10 "2021-04-27T12:26:04Z")

</div>

Sorry guys. I thought I had cracked it but I was wrong. If I have these blocks at the start of the app.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/5/95849b5e151d1678287f89572a8605b9a0fd58bb.png) , everything stops and the app doesnt do anything. I can get to an edit page where I am supposed to be able to update the list but nothing happens when I click the submit button. I hate lists 🙂 Is there something obvious here that I am missing?

---

<div class="post-metadata">

**Author:** ![tony.ycy.program](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tony.ycy.program/32/100153_2.png) [@tony.ycy.program](https://community.thunkable.com/u/tony.ycy.program)\
**Post date:** [April 27, 2021, 12:34pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/11 "2021-04-27T12:34:08Z")

</div>

Empty means `""`  
But Device variables default value is `null`  
`empty string != null`

---

<div class="post-metadata">

**Author:** ![rwplummer1yf4f](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@rwplummer1yf4f](https://community.thunkable.com/u/rwplummer1yf4f)\
**Post date:** [April 27, 2021, 12:59pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/12 "2021-04-27T12:59:30Z")

</div>

Thanks Tony, Looks like you are right. I removed the Empty check and it is working as expected. The logic I had still seems ok to me as I thought the OR would trigger the IF in the event that either condition was true. The second part would be true when first run so set the empty list. When run a second time the list would not be empty and the variable would not be null so the IF would be skipped. Where is that wrong? I cant argue with the results though. Thanks.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [April 27, 2021, 6:13pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/13 "2021-04-27T18:13:28Z")

</div>

I think the reason your app crashed rather than returning false is because you asked it to check if a stored variable’s value is empty (""). But a stored variable has NO value to start with. So the check itself fails. The “if” block never gets to evaluate the “or” section because it’s already crashing.

---

<div class="post-metadata">

**Author:** ![rwplummer1yf4f](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@rwplummer1yf4f](https://community.thunkable.com/u/rwplummer1yf4f)\
**Post date:** [April 27, 2021, 6:30pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/14 "2021-04-27T18:30:35Z")

</div>

Thanks @tatiang. My reasoning was empty("") doesn’t equal no value so the IF condition should work. Logically that is. But I cant argue with the results I am seeing and they do validate what you and @tony.ycy.program @muneer and others have been saying. Thank you for clarifying.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [April 27, 2021, 8:28pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/15 "2021-04-27T20:28:38Z")

</div>

I totally get what you’re saying and I think it’s reasonable to think of it that way. From a human perspective, we think “If A or B” means that you check A and B and if _either_ are true, you return true.

But my guess is that your blocks actually get evaluated in a specific order:

1. Does the stored variable have a value and is that value empty ("")?  
CRASH
2. Does the stored variable have no value assigned (null)?
3. Are either 1 or 2 true? If so, return true; if not, return false.

It’s a little like if I asked Thunkable to evaluate whether “1 ÷ 0 = 6 OR whether 1 x 0 = 6.” It wouldn’t return false because it wouldn’t know what to do with 1 ÷ 0 since it’s undefined.

Anyway, if you stick to checking stored variables for null values on startup, you should be fine! 😉

---

<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, 1:22pm UTC](https://community.thunkable.com/t/how-to-build-a-list-using-stored-variables/1246280/16 "2024-11-08T13:22:53Z")

</div>


