I have searched and searched for an answer to this but I’m coming up short.
In my game, multiple players create a token that represents themself, they are assigned names and Initiative values at runtime by the player and those values are stored in playerprefs.
I’m trying to sort these tokens by descending Initiative values to determine turn order and to display player names in order in a GUI list. It seems like any array that can store a String and an Int as a Key/Value pair (like a hash table) can’t be sorted.
I’m probably missing something really obvious here, but all i need to do is make an array of String(name) and Int(Initiative) pairs, sort the array by the Int(Initiative) value and return the Strings(names) in their new, highest to lowest Initiative order.
so i want to turn some sort of array like this:
token1 with an initiative of 4, token2 with an initiative of 7, token3 with an initiative of 1, token4 with an initiative of 10
into this:
token4 , token2, token1, token3
Also, when a new token is introduced, I need it to slot itself into the correct spot in the initiative order. This would act quite a lot like a scoreboard, where, when a tokens initiative move up the list, the others move down to accommodate it’s new position.
Multidimensional array? Hash table? Some sort of custom sorting? Any help with be much appreciated.
EDIT:
Does anyone know how to pull this off using Javascript?
Thanks so much.