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 !
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
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.
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
@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.
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.
Ok thanks to both of you, Iâll look into it and come back if I have any more questions.
Have a nice day
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 ?
Please check the attached screenshot to see the few more problems I am having now.
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.
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
(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 !)
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 (). 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:
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)
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.
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 ?
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âŚ)