[Solved] Loop with a pause

Hello !!
I have a Loop block with “For each item” in a list that I would like to show 5 items at a time with the last item being a button for “More …”. This way the user can press “More …” and the Loop continues adding 5 more items and so on.

The problem is that the app crashes (only iOS, Android is fine) because I use clone to dynamically create a button for each item in the list. When the list has 52 items, iOS crashes, so i limit my list to have up to 15 items and App doesn’t crash.

If I can control how many buttons at a time are created then i can create all 52 buttons, 15 at a time.

Thanks !!

Carlos

Two thoughts:

  1. When you need a long list of buttons, you might consider using 5 placeholder buttons and changing their background image, text, etc. as needed to give the appearance that list items are changing rather than actually creating a new button for every single item of the list.

  2. If you post a screenshot of your blocks, we might be able to figure out why it’s crashing.

Thank you Tatiang,
Will Send screenshot now.

It only crashes on iOS. Android works fine.

Carlos

I made public:
https://x.thunkable.com/copy/c603115f41da3bb2708f2e3052c7ce25

Thanks,

Carlos

Hello tatiang,
Your idea makes perfect sense. I just don’s know how to navigate through my List. When the user selects the “Soft Music” button, I call web_api to fetch the latest JSON list under the Soft Songs category from my API Server. Then I create my List. Currently I use clone in a for next loop to create x amount of buttons based on the length of the list. With each pass, I assign a Text, background photo and url to each button. After looping 15 times or so, App crashes. So, with your idea I can only clone button1 10 times and in my loop change text, photo and url but how do i navigate through the list back and forth ? The user will need Previous and Next buttons to navigate through the list and that’s what i don’t know how to do. Any examples you can point me to ? Thanks !!

What I’ve done before is to have a pageNumber variable that starts at one and gets increased or decreased when Prev/Next buttons are tapped. Then, in each label or image or button that needs to be updated, you use the pageNumber to help determine what to show. I’m working on something like this now – a student directory – but I’m not really at a place where I can share it.

I used Airtable to select and show the photos… I’m not sure how you’d do this without Airtable. Things like labels are easy because you can use a list and then just increment it with the pageNumber value.

An example of this would be if you had nine labels on each page that you wanted to show at a time, then the first cloned label would show list item number 1 + 9 * (pageNumber - 1). The second cloned label would show list item number 2 + 9 * (pageNumber - 1). The third cloned label would show list item number 3 + 9 * (pageNumber -1). And so on.

Thank you tatiang,
I dont use a db because i have created API libraries so all my servers, apps and other servers can talk to my API Server to get data as json, xml or regular text screen. In this case, the App uses the web_api block to POST to my API server which responds with instructions on what to do. The menu structure is also send to the App the same way and i create my lists.

I got the pagination working just using the Next button and a second counter to limit 10 at a time. No Previous button. I will implement your idea next. My ultimate goal is to have my App display buttons exactly like NetFlix does.

My main problem now is that iOS, not Android, crashes when i press my Home button, which does nothing but call the function that assembles the Main Menu buttons. Another button I press and makes iOS crash, again Android works fine, is a button that displays an Alert showing the value of stored variables. The Alert shows for 500 ms and App crashed. It doesnt happen with Android.

How can I catch the cause of the crash ? And log file i can create ?

Thanks again !!

Carlos

@Carlos_Bieberach you’re welcome!

It sounds like you’ve made a lot of progress and you’ve included some things I don’t know much about like APIs.

As for the crash, I’m not sure. I’ve been seeing some crashes with my projects and other people’s projects today but only in the web preview and Thunkable Live. I haven’t tried downloading them.

I don’t think there are any logs. I use a debugging method where I add on to the value of a label as I step through my program. So if there’s something that should happen first, I do from label set text to [ join with ] “A” and then for the next part, from label set text to [ join with ] “B” and then from label set text to [ join with ] “C” and so on. Then when I watch my project run, I can look for A, AB, ABC, ABCD, ABCDE, etc.

If the program crashes right after I see AB, then I know that the problem is between where I put the “AB” block and where I put the “ABC” block.

An error log would be really helpful, though.

1 Like

Hello Again Tatiang,
I have been writing software since 1981 lol, no typo, 1981.

All my systems interact with each other over API libraries i have been creating for some 12 years now.

Any who, I have been experimenting with Thunkable because i don’t want to depend on App developers anymore. Apps is not my main business. Telecom Servers and Systems is. I want to make dumb Apps that depend on the intelligence on my Servers side. I already created my first one with App Inventor but now I need one for iOS as well, hence Thunkable.

I got the menu working but still it crashes. I call it crash because when i press the HOME button, i get the App’s Splash Window (White Screen with my logo). Only happens in iOS, not on Android.

I totally get your logic about displaying labels and adding an additional letter after each step to find out who did add the new letter/value. Here it doesn’t apply because it is only 1 step, when HOME button is clicked, call the showmenu function.

I have stripped my App to the minimal expression and still crashes:

https://x.thunkable.com/copy/7c8a447ed09da5e207f780613335d956

I’m starting to believe the problem is Thunkable, unless declaring variables that are not being used causes iOS to crash.

Thank you again tatiang for your help and your time. Let me know if I can help with servers and custom made software for your projects.

Carlos

1 Like

I only took a quick glance, but do you think these blocks may be causing issue?

Screen Shot 2020-02-03 at 10.12.49 PM

it seems like the app may want to call btn_Alert, Button1, and Label2 but that they may not actually exist anymore?

So sorry. I removed the “clone” block after i shared the link.

I think you have me beat by at least a year… I grew up in the 80s programming in BASIC on an Apple II. :grin:

I didn’t need to tell you how to debug something with all the experience you have – I try not to be patronizing on the forums (and I’m pretty sure you didn’t take it that way) but I never know if someone is relatively new to programming or not.

I’ll check out your minimal version… @jared may be on to something.

And as for your offer… expect a message from me soon because I in fact do have a project I’ve been working on for a couple years that could benefit from someone with server knowledge.

Thanks!

All good lol

BASICA on TSR-80, Commodore 64 and Tandy our tone Age lol

I appreciate your help and ready here to return the favor.

I removed the clone block after i shared the link.

1 Like

@Carlos_Bieberach 'm sniffing around at the issue here. So far, i am able to get the crash to stop if the ‘any component block’ is not in use. That makes me want to continue to investigate these blocks and what they are doing

issue found

var app btnUrl is loaded as an empty list. the findPositionInList function returns ‘undefined’ and causes the crash i believe

testing now

I think he’s right. The ShowButtons function calls ChangeButtons which adds items to the empty app btnUrl list. But you call an in list app btnUrl get command before you call ShowButtons.

1 Like

Hey @Carlos_Bieberach! Let us know if that helped out at all. Hopefully you were able to figure it out!

That was the issue !! You found it !!

Main Menu (called by the HOME button) doesn’t come from an API call (JASON or CSV), it has its own value for url. In this case, the url is a one digit value that is sent to the API Server which returns the data that will be used to created the requested sub-menu. That sub menu is created with the CLONE block. When the AnyButton block is called, the submenu doesn’t fail since it was created by the Clone block, which adds the url to the list. Menu Main fails because it wasn’t created by the Clone block.

Thank you jgibb20189

1 Like

Thank you tatiang for your support as well !!