Index of maximum value in array

I want to save the index of the maximum value in an array as a variable to then evaluate an array at that index. I’ve thought about this for a long time but can’t figure out a way to do it.

I’ll provide some context on what I’m actually trying to accomplish. Maybe there’s a better approach that I haven’t thought of:

I’m making a deathmatch where players vote on what hero everyone will be. I pick three heroes by generating three random integers and storing them in elements of an array, say “Rand” I have a global variable, “Vote”, which keeps a tally of how many votes each hero has received. So Vote[2] represents the hero generated by Rand[2].

Let’s say Vote[2] is the highest value in the array, receiving the most votes. How do I then force players to be HeroArray[ Rand[2] ]

Last Of(Sorted Array(Rand, Vote[Current Array Index]))

I kind of figured it out right after I posted this. Here’s what I did, probably not the most elegant solution:

Global.Index = Index Of Array Value(Global.Vote, Last Of(Sorted Array(Global.Vote, Current Array Element)))

Start Forcing Playing To Be Hero(Global.Players,Global.HeroArray[Global.Rand[Global.Index]])

Hopefully if others come across this problem they can find this thread with people offering solutions.

1 Like