"Find first" that returns index

Is there a built-in block that is like "find first" (that takes a predicate) but returns an index instead of the value of the found item? Thanks.

Great question! There isn't a built in block that does this automatically. However, you could wrap "find first" in "item [index] of [list]". This will give you the desired result. Here is a visual example:

So, in this example, it will report "2"; since, two is the index of item 1 in the list.

This is my fault, because I specified the behavior of the block. Of course it should report the index. I realized that just a couple of weeks after we released the software, but of course by then we were using it all over the place in BJC and elsewhere. :~(

Now that we have Swiss-Army-knife blocks such as LENGTH OF, I'm gonna try to talk Jens into
Screen Shot 2022-05-06 at 2.44.11 AM

Thanks for the answer. That is how I tried to make it at first. But two issues: First, doesn't that do a look up twice? Second, if the boolean test involves the element's position (or running total or something else other than its plain value) to decide its true/false value... wouldn't it give the wrong lookup if, let's say there is more than item whose value is 1? Like you have a potentially complicated boolean followed by a simple value lookup that may not pick the same value?

I think I could write the custom block maybe, but I thought it might exist. Maybe not. This is really helpful either way. Thank you for helping me.

Right you are. And yes, I'm sure you can write it.

Here's the way I like to do it

And if you want this to work with empty lists, just do

We just saw your reply too. Thanks Professor Harvey! I am working to make my game even better since you extended the deadline. It is going to change the questions it asks based on which ones you get right or wrong. My Dad is helping me with the list stuff. So far we used map, but we need to do some filter and reduce too. That is why we needed some index stuff. Thank you. :grin: :crazy_face:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.