Reading from a List
CreatiCode last edited by info-creaticode
A list is just like many variable items positioned sequentially. You can read the value of any item using its position, or get information about the list itself.
This reporter block tells you how many items are in the list.
Note that the position indices of the items go from 1 to the list length. For example, if you want to insert an item before the last item of a list, you can use the list length as the position.
If you know the position of an item, you can read its value using this block:
The position index has to be at least 1 and at most the length of the list. For example, to get the last item’s value, you can do this:
You can not only get an item by its position, but also find the position of an item if you know its value.
If the value is not found, then the reported value will be 0:
You can find out if a value is contained in a list using this boolean block, which will report “true” or “false”.
Sometimes you want to find any item that contains some value. In other words, you are searching for a part of an item. You can use this block:
For example, in the list of student names, you might want to find the index of the first item that contains “Mike” like this: