• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Get Highest Integer

Status
Not open for further replies.
Level 6
Joined
Sep 19, 2005
Messages
169
I'm probably missing something very simple here... But basically I have some variables that are assigned to players. How can I find the highest income for an array variable. In my situation, the integer variable is called "Income", and each playing player is assigned a value based off their player number. How can I check to see which integer is the highest, which is the second, and so forth all the way till the lowest value? (The whole purpose is to sort a multiboard based off whoever is has the highest income)
 
Level 1
Joined
Jun 7, 2008
Messages
6
Hello I'm a random stranger from the internet, but I remembered this one map that assigned ranks to each player in the multiboard. 1 to the player with the highest score 2 for the second highest player and so on. So I figure that is one step away from solving your problem. I think the trigger that controls it is this one. The last part seems to be the important thing, but it's too late for me to check tonight.

Player Group - Pick every player in BuilderPlayers and do (Actions)
Loop - Actions
Multiboard - Set the text for Scoreboard item in column 4, row ((Player number of (Picked player)) + PlayerScoreBoardRowOffset) to (String((Number of players in (All players matching ((((Matching player) is in BuilderPlayers) Equal to True) and (Scores[(Player number of (Matching player))] Greater than or equal to Scores[(Player number of (Picked player))]))))))
 
Level 15
Joined
Jan 31, 2007
Messages
502
  • Do Multiple Actions For each (Integer A) from 2 to 12, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Income[(Integer A)] greater than (>) x
        • Then - Actions
          • Set x = Income[(Integer A)]
        • Else - Actions
After this loop x will contain the greatest vaule
 
Level 3
Joined
Jul 20, 2008
Messages
41
Its what johnny posted and each time you do this you could somehow exclude the largest number to find 1st,2st,3rd etc.
 
Level 9
Joined
May 27, 2006
Messages
498
Just use Multiboard - Sort by descending (from highest to lowest) order.
Or, in case you would want to get the highest integer for different purposes, just use
  • Actions
    • Set integer = Max(number1; number2; number...; numberN)
@Up
The "bolded x" is an integer-type variable.

@Down
Yeah, forgot to add that it's already been said by someone here :X
 
Last edited:
Level 4
Joined
Nov 23, 2007
Messages
113
If you want to sort an array you can use a simple gnome sort function.

JASS:
// sorts from highest to lowest value
function gSort takes integer numElements returns nothing
   local integer t
   local integer i = 1
   local integer j = 2
   
   loop  
      // numElements is the number of elements used in the array
      exitwhen i >= numElements
      
      if ( udg_income[i-1] >= udg_income[i] ) then
         set i = j
         set j = j + 1
      else
         // swap elements
         set t                = udg_income[i-1]
         set udg_income[i-1]  = udg_income[i]
         set udg_income[i]    = t
         
         set i = i - 1
         if ( i <= 0 ) then
            set i = 1
         endif
      endif
   endloop
   
endfunction
 
Level 4
Joined
Nov 23, 2007
Messages
113
Paste it into the map's custom script and call it with something like this:

  • Custom script: call gSort(12)
PS - And by "simple", I was referring to the fact that a gnome sort is considered non-complex and unoptimized (i.e. a simple algorithm). The term wasn't meant to insult anyone's intelligence.
 
Status
Not open for further replies.
Top