List in variable?

Can a variable store a list?

Yes

Only the new ones, and you maybe want to store your list as a text and make it a list everytime the app opens to avoid bugs

please explain more
sorry for saying this every time:pray::pray:

The old variables can also be will keep using Local Storage. Nothing complicated here. Create a list and assign it to global variable of type “storage”.

Old variables couldn’t keep full lists but could be used to make list from text, I experienced that and got me stuck with an app :confused:

@Farshad, you have a block Make list from text with delimiter

If your text is : A,B,C,D
And if your delimiter is ,

Then your list will be :
A
B
C
D

And so you can store a text and split it into a list everytime you need it. Also don’t forget that if you want to remove an item from the list, you need to remove it from the text you’re saving :slight_smile:

Nice day ! :slight_smile:

Our last release fixed the worst issues with saving lists in variables.

There is still a relatively small bug if you happen to create a list of lists (or list of objects) and modify one of the inner lists (or objects) within the outer list, but if you are not doing that I would suggest just saving the list in a variable and not bothering with storing it in text or anything like that.

If you do happen to modify lists (or objects) within lists the workaround if that you’ll need to explicitly re-save the list after you modify the inner list (or object).

-Mark

-Mark

Hry @Mark, I didn’t see the bug fix on my side, I cannot store my lists in themselves inside the variable and get them back in my listviewer when the app reopens, that’s why I suggested the text workaround. Also I forgot to mention that with the text workaround, you will have a blank element at the top or at the bottom and you won’t be able to avoid that (as far as I searched)

Nice day :slight_smile:

When I spoke about old variables, I meant such blocks. It works for me. Did it not work before, or are you talking about some other way to save lists?

I was talking about a workaround with the current variables, we misunderstood hahaha

@AcrobatEpee, It was never intended that simply modifying the list that you set the List Viewer’s TextItems property to would affect the ListViewer. It happened to work previously, but that was an accidental property of the implementation. You need to re-set the List Viewer’s TextItems property to the modified list after changing it.

-Mark

1 Like

Yeah, i think i have the same question.

from the platformx docs:
A stored variable also works across screens but is saved to the mobile device itself. This means that a stored variable can be retrieved from a previous session. A stored variable is similar to saving a value to Local Storage and is especially useful for retrieving a user’s previous setting. If you use stored variables, you no longer need to add Local Storage to your app.

But how could you initialize a stored variable to a list?

Your varisble is your list, so when you want to add an item to your list, use the insert in list yourvariablename block

How can you re-save the list?

fyi, this is the list created from realtimedb

it appears that when the list item (either original or the new one resulting from the removing of items) is now index 0, it is “removed” from the length of the list (because the number on the label decreases everytime the button is clicked), but it is still displayed on the labels, hence… duplicated results in the get random.

David,

I’m not sure I understand your question. For one, when you remove an item from the 'stored name' variable you shouldn’t need to then set the 'stored name' variable, i.e. you shouldn’t need that block that you circled. If you’re saying that getting a random element of the 'stored name' list is sometimes returning an object that you had removed, then that is a bug! If that is the case, can you create a very simple app that demonstrates the bug and share it with us? If it is not the case, can you give us some more details on what the problem is?

-Mark

Hey, here´s a simple project showing that behavior everytime button 1 is clicked, however I use my own firebase account to get the list, idk if you need my api key and URL to replicate, or you can use your own and just recreate the same simple Q&A list I showed you in an earlier post.

https://x.thunkable.com/copy/aae2618a6fcbbb28ff0acb352e9976f1

PS: I used the circled Set block because that´s what I thought I understood when you said in your post to “re-save the list” if you modified objects, my bad haha

David,

Sorry, I should have realized that you are talking about the same problem that you described in Problem while removing an item from my list and for which I explained in my comment here that we have a bug. Unfortunately we haven’t yet fixed that bug.

I think that a workaround would be to select a random item by using the Math category’s 'random' block (giving it the length of the list as the value of the ‘to’ slot) and using that random number to remove the appropriate item from the list.

-Mark

Hello there, thanks for tour suggestion. Is this what you meant? Because if it is, I´m still having the same bug :frowning:

David,

In the 'Button1 Click' block you want to set 'app card' to select which item using your random number, i.e. 'app random'. You do it correctly in your 'Screen Opens' block, so you should be able to just copy the blocks that say 'set app card to ...' from there. I tested out something like that and it appears to work.

-Mark

sorry for the delay, I was doing a lot of tests and solving other issues that came along. Your solution finally worked! Thanks.