Highest int from array of structs

Hello,

I have an array of structs that I call “PossessionList”, in which the structs are made up of one enum and one integer. I was wondering, what is the easiest way to get the highest integer from this array?

My current workaround is to loop through the “PossessionList” and add the integers to another array, called “NumOfPlayersList”. On completed I then use the “Max Of Int Array” node and input “NumOfPlayersList” and then it outputs the highest integer from that array. But this seems very complicated and I believe there is an easier solution to it, which I’m not aware of atm.

So is there an easier way for me to get the highest integer from an array of structs? Thanks in advance :slight_smile:

~Stefan

You can check which is highest just by iterating over the array.

The Highest Index variable should be accurate after that.

Thank you for the quick response :slight_smile:

This was my previous workaround, but I decided to store the “Highest” variable in an array instead because it is more flexible and organized, as I can use the “Max Of Int Array” node to get the index and value of the highest integer. I guess both of these ways works completely fine and accurate, I’m just trying to explore for different opportunities.

Thanks again!

If efficiency matters, you could store a HighestSeenValue variable too, and every time you add a struct to the array, you can set that HighestSeenValue to the Max of itself and the incoming value. When you remove a value, if it is equal to HighestSeenValue, you will have to loop over the whole array to find the highest one again though, unless you were also keeping track of the second-highest, and the third-highest, etc.

Hello mightyenigma,
I totally forgot to mention that the array-elements are fixed, which means I’m not creating it with any kind of logic. If that wasn’t the case tho, I must admit your workaround seems the most useful so far.
Thanks for commenting!