Download

Finding middle values in array?

In my current blueprint I am able to determine 1st place and last place by finding the max and min values of an int array and using their index values as references to their player controller id’s. This doesn’t seem to let me determine the 2nd and 3rd place though. There is no Find mode of array or anything is there?

There is a get node which takes an array and an index integer. This is what you want im pretty sure.

Your best bet is to probably find max, and then remove max from the array, and then find the new max in order to get 2nd place.

It’s starting to seem like it. But then I can’t determine which player has 2nd place because the index wouldn’t match up. Also if two players have the same score they will both be identified as 2nd place.

The get node unfortunatley wouldn’t do me any good unless I wanted to call it for every possible outcome

In that case, just use this method to sort the array: Sorting Float Array Numerically? - UE4 AnswerHub

Is there anyway I can preserve index values this way? Say I take the value from PlayerScore array at index 3 can I add it to the new array at index 3? Otherwise I can’t figure out which player had that score

Yeah, say you have 27 as index 0(the highest score, or lowest?), you could do ‘Find’ for 27 in your unsorted array in order to find out which player had that score. This shouldn’t be an issue with multiple players having the same score, as you are basing it off of an index with just an int.

Make a copy of your stats
sort it from lowest to largest
choose your “place”
use “find item” in the original scoreboard array, to find exact index of your place

OR store everything as structs, google for “bubble sort” implement it.