List index behavior

listview
lists

#1

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

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


#3

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.


#4

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.


#5

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


#6

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.


#7

@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


#8

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.


#9

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


#10

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.


#11

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

thanks


#12

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?


#13

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


#14

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.


#15

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