Problem repeating item in list viewer

Hey !
I have a listviewer on my app and I want to add items to it. The problem is that it only adds the first item and all the ones coming next are not inserted inside the listviewer. May someone tell me why is that happening and give me a solution please ? Thanks !

Here are my blocks :

(I know it is the same value that is inserting again and again but the thing is just that it is only inserting once) :slight_smile:

hey @AcrobatEpee,

thanks for posting this question.

your blocks give a nice overview about the issue.

the first information, that might help you is that the “repeat”-loop will rapidly do the tasks in the “then do”-section.
You have put local-storage components here. -> I recommend to use variables (orange) and use the blue add-to-list components

Cheers,
User81

1 Like

So it might mive something like :

Set variable “storage” to join :
-From list viewer get items
-join :

-name
-spaces
-score

From listviewer set textitems to variable storage

Is that your idea ?

image

Like this ? It won’t work, still shows me the first item only

May you send me the blocks you’re talking about or maybe the result you want to me to get. I’m not doing this for you to make the app for me but to be able to understand and to make future people understand. We’ll sure explain this fully so everybody can enjoy at the maximum.

Thanks in advance !

https://x.thunkable.com/copy/60c884165aabe716e17b77580eb13046

1 Like

So this should work right ?

Because the problem with your selection is that I first need to write down all my items but in my procedure the items are getting written everytime the procedure runs again so I need it to write the items on the go, I’m gonna try the screenshot I sent you and tell you how it looks :slight_smile:

Thanks !

@User81

When I do this :

It gives me this :

Note that here the label shows the “name” variable but it in the listviewer it doesn’t show. May you tell me why please ? Thanks !

By the way your solution worked except for this ! Thanks a lot :slight_smile:

please change the green null-block to a red textblock with “null”

1 Like

@User81 it doesn’t change anything. Please see the upper post where I point out the fact that the value isn’t null because it is needed for the next step and the next step is working fine. So I don’t think the “null” was the issue.

Thank you for helping me! Looking forward to your reply !

I cannot help you. using loops and local storage at the same time seems impossible for thunkable. please save the list of friends as a list to text and get it from there.

good luck, bye

1 Like

@Mark Is it really impossible to use localstorage in loops ?

@User81 Can you explain this please ?

Thank you :blush:

It’s not impossible, but it can lead to unexpected results in certain circumstances. The basic issue is that 'LocalStorage.Get' (and Set) is currently an asynchronous operation, meaning that it is executed more-or-less at the same time as the blocks that come after it - including blocks that come after it in a loop. That’s we we have the 'then do' slots, which tell the 'LocalStorage.Get' what to do once it gets a result.

This affects your loop in that all the 'Users.Get' blocks will execute at more or less the same time. Moreover, they will all happen at more or less the same time as your loop is incrementing the 'Friends' variable! So the value of 'Friends' with the 'Users.Get' blocks could be just about any value between 1-25 in any of the 'Users.Get' blocks.

I wrote a little more about this sort of problem in Asynchronous Blocks within Loops. It also contains a workaround for how to deal with such issues.

Also note that we are thinking about possible solutions to this issue, but have no timetable yet.

I’ll also just note that @User81 is correct that you need test for the string “null” rather than the using the green null-block. I know it’s confusing ;-( . He’s also right that it would be easier if you could just save and get the entire list at once. Then you can loop over the list and have fewer problems.

-Mark

2 Likes

Ok thanks to both of you, I’ll look into it and come back if I have any more questions.

Have a nice day :slight_smile:

Hey @Mark ! Your tutorial stands for saving the value if I’m not wrong, but I just want to gather the information and here the realtimeDB is not at cause because the loop gathers the information from RealtimeDB with the use of the “name” variable, but still isn’t able to show this variable in the final list.

UPDATE :

I used a workaround that wasn’t listed in your topic but maybe you could add it :blush: ?
Please check the attached screenshot to see the few more problems I am having now.

UPDATE : The not showing value issue was fixed by inserting the set textitems into the userFB then do

Thank you for helping me !

The fact that my tutorial deals with saving and not just getting values is not really relevant. The relevant part is converting the loop to a recursive function (i.e. the ‘AsynchLoop’ function in my example). However, I can understand how it might not be obvious how to adapt that function to your case.

Your workaround to wait a second is a little too hacky for my taste. For one, if you’re looping over a lot of items the delay will be considerable. Also, you don’t really know exactly how long to wait. That said, I am glad that it works for you!

For the ListViewer issue you mention, if you have too many items in the list to fit within the height of the ListViewer, that’s the expected behavior. You might need to adjust the height of your ListViewer.

For the ordering problem, it looks like your TextItems list is not numeric, i.e. does not simply contain numbers. Unfortunately, switching to alphabetic sorting will like not work either since I assume that you want to sort by score. To do the sorting you want you’ll have to do something more complicated and sort them in some separate function where you parse the text items to extract the score.

If you do as @User81 suggested and keep things in lists you could potentially use the list sorting blocks.

-Mark

1 Like

Could you help me set up this / give me a block example of how I should set up this in my project because you’re right, the delays can become very huge :confused:

(I can’t really understand what is an AsynchLoop even after looking at your tutorialand how to insert it or adapt it to my example (what should I replace or change, etc.) but I’m really looking forward to learn how to use this and make my apps more reponsive !)

I tried this but I for sure mistaked somewhere, may you guide me please ? :blush:
Thanks for you help @Mark !

let me try to give you a picture of loops, that are asynchronous (“async”):

you have ten people in a row in front of you. But instead of fast counting the people really fast from left to the right, you tell every one really fast: bring me a beer (:beer::grin:). Now you have told everyone and do other things, while the people are running to find a beer. from now on you have lost control over when they will come back with beer.

everytime, one of the people comes back with beer, one then-do-section is triggered.

what can you do to bring some order to this issue:

  1. waiting: you could use the timer component ore the wait for X seconds component and estimate a time, when everybody is back. (I would not recommend that)

  2. you count, how many of them have returned yet and when the last one comes back (with beer of course), you do your next operations. (see example below)

one last thing: in the project you showed us in your posts you want to get a value and then use this value to get another value: please do not do this, because it is complicated enough to do one async loop.

1 Like

I don’t get it but got the fact that you had no time to get this personnal. Is there someone kind enough who’d see no problem taking some time to explain me in private how tu use asynch blocks please ?

Thank you !

hey @AcrobatEpee,

I thank you for being a vivid part of the thunkable community. And in fact I really took my personal time for you (stopped working on my projects to build iOS projects to share and making screenshots and trying to understand your problem and explaining)

Sorry for not sharing my personal mobile phone number with you. Maybe you will find someone who can do that and I hope you will share your solution with the other lovely members of the community.

The fruits you want to pick are right in front of you. Either you use the recursive design of @Mark , which does not use the loop components (repeat…times, from-1-to-10-do…, while…do) or you use my design which I would describe with sending all orders on one instance and then wait for the last one to return (if-length of returns=length of orders->then do…)

Cheers,
User81

1 Like