HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Finding the highest number in an integer array?

03-11-2006, 03:01 AM#1
ZafalTheWaffle
Hi I would like to make a trigger so that the player with the highest kills wins, so it goes like this:
Everytime you get a kill it adds 1 to the integer Kills (player number of (owner of killing unit)

Now lets say that at the end of the game the kills go as follows:
Kills [1]=50
Kills [2]=23
Kills [3]=17

How would I make a trigger that identifies which one of these is the highest?
In other words, how would I make it so that the Player Number of the Player with the highest kills wins?
03-11-2006, 04:22 AM#2
Immoralis
you need 2 for loops, one to go through all the integer arrays and the 2nd to compare them to the rest, or you can do 1 for loop that takes the kills and goes through and if its higher than the current, it makes that the highest
03-11-2006, 04:54 AM#3
PerfectlyInsane
There is a max function though I not sure how to use it.. maybe you can google it.
03-11-2006, 05:38 AM#4
blu_da_noob
Create a variable 'Max' with an initial value of 0. Loop through the array and if the value of the current index in the array is greater than 'Max', then set 'Max' to that value and set some player variable to that player.
03-11-2006, 12:27 PM#5
Drakim
blu da noob is right, that is by the far easiest way to do it (if there hasn't been done a max function before in the program).
03-11-2006, 12:59 PM#6
Whitehorn
Simple sorting algorithm :) GJ Blu :)
03-11-2006, 03:21 PM#7
blu_da_noob
It's not even a sorting algorithm.
03-11-2006, 05:12 PM#8
TaintedReality
Shh, using the word algorithm makes you seem hardcore =D.
03-11-2006, 05:17 PM#9
Captain Griffen
It doesn't sort, but I think it still counts as an algorithm.