1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  4. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  5. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Get Highest Integer

Discussion in 'Triggers & Scripts' started by PsycoMarauder, Jun 1, 2009.

  1. PsycoMarauder

    PsycoMarauder

    Joined:
    Sep 19, 2005
    Messages:
    173
    Resources:
    3
    Maps:
    3
    Resources:
    3
    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)
     
  2. VigorousApathy

    VigorousApathy

    Joined:
    Jun 7, 2008
    Messages:
    6
    Resources:
    0
    Resources:
    0
    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))]))))))
     
  3. Lord_BoNes

    Lord_BoNes

    Joined:
    Sep 5, 2007
    Messages:
    264
    Resources:
    0
    Resources:
    0
    By memory, a leaderboard can be told to sort itself... Can't you do that with a multiboard?
     
  4. -JonNny

    -JonNny

    Joined:
    Jan 31, 2007
    Messages:
    486
    Resources:
    12
    Icons:
    3
    Maps:
    4
    Spells:
    4
    Tutorials:
    1
    Resources:
    12
    • 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
     
  5. Seth21

    Seth21

    Joined:
    Jul 20, 2008
    Messages:
    41
    Resources:
    0
    Resources:
    0
    Its what johnny posted and each time you do this you could somehow exclude the largest number to find 1st,2st,3rd etc.
     
  6. VigorousApathy

    VigorousApathy

    Joined:
    Jun 7, 2008
    Messages:
    6
    Resources:
    0
    Resources:
    0
    So you could make a player group and remove one player at a time from it.
     
  7. PsycoMarauder

    PsycoMarauder

    Joined:
    Sep 19, 2005
    Messages:
    173
    Resources:
    3
    Maps:
    3
    Resources:
    3
    greater than (>) x

    What do I put where the bolded x is?
     
  8. raft_pl

    raft_pl

    Joined:
    May 27, 2006
    Messages:
    496
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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: Jun 2, 2009
  9. Lord_BoNes

    Lord_BoNes

    Joined:
    Sep 5, 2007
    Messages:
    264
    Resources:
    0
    Resources:
    0
    That's what I was meaning earlier. I couldn't remember the exact name of it (I'm a little rusty with GUI) but I knew that there was something like that. :thumbs_up:
     
  10. Mannoroth

    Mannoroth

    Joined:
    Nov 23, 2007
    Messages:
    113
    Resources:
    0
    Resources:
    0
    If you want to sort an array you can use a simple gnome sort function.

    Code (vJASS):
    // 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
     
     
  11. VigorousApathy

    VigorousApathy

    Joined:
    Jun 7, 2008
    Messages:
    6
    Resources:
    0
    Resources:
    0
    k now explain to someone who doesn't know jass how to import that.
     
  12. Mannoroth

    Mannoroth

    Joined:
    Nov 23, 2007
    Messages:
    113
    Resources:
    0
    Resources:
    0
    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.
     
  13. VigorousApathy

    VigorousApathy

    Joined:
    Jun 7, 2008
    Messages:
    6
    Resources:
    0
    Resources:
    0
    Okay you're forgiven for the "simple" thing, but that doesn't excuse you from calling me a gnome!