Strange Behaviour Of List Indices

Hi,
in the app I’m making the indices of my lists are acting weirdly. If I am looking at the screen open on the live testing then all of my lists in the code for that screen work properly on the live testing with no issues. But if I am looking at a different screen then the lists act like they start at 0 instead of 1 and this messes up the live testing of my app.

Has anyone else encountered this issue? Any suggestions for fixes or workarounds are welcome.

Hi @SuspiciousLukingPlnt, yes I have similar problems in ThunkX with lists:

  • in an App with multiple screens there seems to be a difference in iterating through a list when another screen is opened in blocks or not
  • iterating with a double loop does not work correctly (I played around with a bubble sort algorithm, which uses two nested loops)

Hi @SuspiciousLukingPlnt and @Michael_Rogulla could you share a project, either here or via a PM, that demonstrates this issue? thanks

Hi @domhnallohanlon

I found a workaround and have already implemented it. It would take some back tracking to get that problem. If I run into the problem again I’ll make sure to send it to you.

If its of any use to anyone, my workaround is this:

In my database I make the first item in the list ‘¬’, I then have my code see if that’s in the first position. If it is I have the 1st item I want as the 2nd index, and so on.
If it can’t see it, it means that the indices have messed up and skipped it so I have my code just take the 1st item I want from the 1st index, and so on.

That’s been working for me so far

1 Like

Hi @domhnallohanlon,

As pointed out by @SuspiciousLukingPlnt and @Michael_Rogulla, there appears to be a bug in the “in list get #” block when used in combination with a list viewer. I’ve created a simple app to demo the bug at https://x.thunkable.com/copy/aeb9a9da63b58cffe82a2b4a9464fde5

Instructions to reproduce the bug:

  1. Make a copy of the demo app.
  2. Open Screen2 in the block view.
  3. Live test the app. Notice that whichever list item you select on Screen1, the corresponding list item is displayed on Screen2.
  4. Open Screen1 in the block view.
  5. Live test the app. Notice that whichever list item you select on Screen1, the incorrect list item is displayed on Screen2 (shifted by index + 1).

I haven’t found a good workaround for this bug – other than keeping the correct screen open in the block view. Any advice is greatly appreciated.

Cheers,

Guido

1 Like

Hi all (@guido, @SuspiciousLukingPlnt, @domhnallohanlon), today I found that I cannot trust the “count with” - block with lists:

  • create a “count with” block like:
    – count with i from “1” to “length of list” by “1”
    – do … in list get #i

… will not work correctly. In my case the first item will be forgotten! I have to explicitly take the number-block from “Math”, insert it in the slots in the “count with” - block and fill in the number “1”, even if it is filled with a “1” by default.