question

Zixuan Xiong avatar image
0 Likes"
Zixuan Xiong asked Matthew Gillespie edited

Array Index from Array Value

How can I get the index number in an array based on the array value?

For example the array label showing below. Is there a function can search token id: 1050 inside a array and return the index value 2?

FlexSim 7.7.4
codearrayarray index
untitled.png (7.8 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

LeGrand Gold avatar image
5 Likes"
LeGrand Gold answered Zixuan Xiong commented

Put the following in the Value field of an Assign Labels activity:

treenodearray pallets = getlabel(token, "pallet");
return findmatch(arraysize(pallets), gettokenid(pallets[count]) == 1050);

You can read more about findmatch in the user manual. Basically, it is a for loop that returns the count where the second parameter was true. In this case, it returns the count where it found token ID 1050.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Zixuan Xiong avatar image Zixuan Xiong commented ·

Thank you! That's the function I'm looking for.

0 Likes 0 ·