Finding the highest value in a group of ints

Hello all,

I have a small problem that I wanted to share:

I have an integer array (used to store the score values for four players), and at a certain point I need to be able to look at the values in this array and find out which player has the highest score. I know that the “Max of Int Array” node exists, which would be fine for my purposes if it wasn’t for the fact that in my project it’s possible (and likely) for two or more players to have the same score. The problem with that node is that as far as I’m aware, it isn’t equipped to output more than one result in the event of a draw.

So I’m looking for another solution. I need to be able to compare four integer values and pick out not only the highest value, but also whether or not two or more of those values are the same and therefore causing a tie.

Thanks for reading,

Hah, so I actually just solved this on my own 15 minutes after I asked the question. I’ll post my solution here for anyone who comes across it.

I ended up still making use of the “Max of Int Array” node; I saved the result value to a variable, which was then used to compare against the score of each player (in a for each loop). When a player’s score matches the max value, the player index is stored in a new array. When the loop is finished, the number of entries in the new array is counted. I know for certain that there will be at least one player in the array, so I perform a simple test to see if the array length is more than one. If it is, we know that there’s a tiebreaker situation; and if it’s not, then we know that there is a clear winner.

I hope that makes sense. Please forgive the rushed explanation, it’s just turned 3am and it’s way past my bedtime :D.

This works if you aren’t trying to find 2nd 3rd 4th place do you have any idea how to find the remaining index values?

Haha wow, it’s been over a year.

You could use a similar system that does the above, and then at the end of that process removes that entry from the array. Then you’d do the process again as many times as you need in order to get 2nd, 3rd and 4th.

Question is very old, but since Google still finds this topic, I will post an answer to this which I found to work.

Removing the 2nd, 3rd, 4th, etc. indexes from the array will cause problems, since the numbering of the array will automaticly be adjusted to higher position. It only works if the last person in the list is winner, the other above him second etc. if first person wins and his index will be removed, the following index numbers will be out of order.

Instead of removing the index, use “Set Array Elem” node and adjust the value of the picked up index of the winner to 0, so that in following checks when the 2nd and 3rd place are taken via “max of int array” as above, he wont be picked up again as his integral is 0 now.