Index of true values in a spread

Hello everyone :)

How can I have the index of true values of a spread in gamma?

In beta I was used to use the node select, but in gamma i don’t think it is the correct node to do this:

Thanks a lot,
have a good year ;)

Hey @Martina1

You could use a ForEach region to achieve such a thing. I would suggest watching this tutorial first to get an overview of how to use it :

Now to answer your question, you could use the following :


What’s happening here is that we’re iterating over all the slices of the input spread of integers, and we are exiting or “breaking” the loop when the condition is satisfied (here : when the value is equal to 3).
We then connect the Index pin to the accumulator output of the region (the one that has a diamond shape) : doing that will always only return the last value of the iteration.

Since we are breaking the loop when the condition is satisfied, the accumulator gives us the index of the slice that satisfies the condition.

If you want to get all the values that match your condition, you would rather do it like that :


You can see it’s almost the same thing with two differences :

  • We are not using the Break pin of the region, but rather Keep : this kinda acts like a Select in beta : for each iteration that sets this Keep pin to True, the value is outputted from the region.
  • Second difference is that we’re not exiting the region via the accumulator, but via the splicer (funnel thing). As I wrote earlier, an accumulator would only output a single value, but the splicer always outputs a spread. So here, it returns the indices of all slices that match the condition (which again here is = 3).

Now you could argue that you could as use the second example with a FirstOrDefault node if you’re only interested in the first slice :


But I find the first one to be more straightforward :)


Wow, very exhaustive answer!

Thanks a lot @sebescudie !! :D

1 Like

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