List index behavior

Are lists indexed starting at 0 or at 1? I have blocks to get an index from a listviewer item clicked that lines up with a list of objects and I had to set the index to “index-1” from the listviewer to index the objects correctly, but eventually as I use the app that behavior changes and indexes the object one earlier than i want.

Example: I click the second listviewer item and the blocks that set the variable “app idx” subtracts one from the listviewer index to make “app idx” 1, which indexes the second object in my list of objects. But after a few correct attempts clicking the second listviewer item selects the first object in my list of objects, without changing that block.

2 Likes

Are you adding to the list with the add to list block ? If yes make sure not to add at last or at first and set the first item to #1

1 Like

Indexes in ListViewer and List are indexed from 1. Index 0 means that there is no item in the list when trying to get it.

3 Likes

Right, so listviewer starts at 1, do lists start at 1 too, or 0 like in code? Basically however lists are indexed seems to change.

1 Like

Indices in the list should start from 1. But due to an internal error, they can start from 0 in some cases. If your index starts at 0, then let the developers know.

%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5

thank you for the info. I found a work around that will be helpful to anyone with similar issues. Rather than setting an app variable to an index number, my list is a list of objects so I search my list for any object that contains the item clicked and set an app variable to that object. I can make any changes and insert it back to the list by doing a similar search for the object with properties equal to my current object.

2 Likes

@Michael_Mckenna . Can you create and share a simple example of an app that demonstrates the problem that you are seeing? That will help us diagnose the problem.

As far as we can tell indexing always starts at 1. We have some other bugs, unfortunately, that we think can make it look otherwise, though.

Thanks for your help.

-Mark

2 Likes

I had exactly the same problem with block “in list get # __” , sometimes index started at 1 and sometimes it started with 0, either on android or iOS live app. However it always “corrected” when I re-enter same index numbers starting from 1 (i.e. doing nothing new)

I solved it by replacing with block “get property from object”. Here are my current blocks, I hope it helps.

1 Like

As far as I know I believe that we’ve fixed the problems that led to it appearing that list indexing sometimes started at 0 rather than 1. If you are still seeing this error, please let us know and, if possible, send us a share link to a project which displays the problem.

Please do not use the 'get property of object' block to do list indexing. The fact that that works is an artifact of our particular implementation of Lists that we might change in the future.

-Mark

1 Like

the issue was still happening to me a couple of days ago so apparently it was not completely fixed or my project is weird enough to recreate the problem haha.
I dont have anymore a copy of my project with the old blocks causing the problem, I just have the project with the blocks that I showed on my previous message, idk if that still helps so let me know if you still want to take a look so I can share you my project.

Hey there, as a suggestion from @actech I solved my indexing issue by using “create list from text with delimiter” block

thanks

1 Like

False alarm :frowning: even with the partial solution by @actech, the indexing weird behavior happened again today. Would you like a link to my project so you can take a look?

1 Like

Sure. And can you send me clear instructions on how to demonstrate the problem? Also, will this require any explicit API keys or are you using the defaults?

-Mark

You are right, my method does not eliminate the indexing error, because it uses blocks in which this error is contained. Unfortunately, the indexing error for large projects has not been resolved.

Thanks for your help, I have already sent my project to Mark for him to take a look at the issue.

Hi all, same problem here, my list index sometimes starts with #1 others #0.

it’s a bug or is my code wrong?

When working with a list, protect against the wrong index. If there is an element under the index 0, then enter the correction for the indices. This is a bug that will exist for a very long time or forever.

what type of correction do you suggest?
duplicate the function and shift index by “-1”?

If the index starts with 0, then enter a variable with the value 1 and subtract it when calling the functions for working with the index.

Or you can try so.

or so

%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5

1 Like

This is getting awkward as the Schrödinger’s cat:

I’ve been having problems with list viewer since 2 minutes ago, when I wrote this post:

if I select the last one (or if there is only 1 item), and ask the app to read the content, it says it’s empty 90% of the time.
Should this seemingly complicate solution fix it?

I’ll try it

But now the app is just working fine. absurd.

Screenshot_2019-07-08%20Thunkable

And firebase list starts from 0 while listviewer from 1

AAAAAND now it’s back to NOT working! :sob: