• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] How to make this shorter

Status
Not open for further replies.
Level 13
Joined
Mar 24, 2013
Messages
1,105
I'm trying to check for which player has the most points at the end of the game, TotalPoints is an integer array, and the index on the array corresponds to the players GUI player number. I could do more of what I have below but it will be a huge block for no reason and I know it could be much less code but I can't figure how I would use For Each Int from 1 to 11, or some faster/shorter way. Thanks for any help.

  • End
    • Events
      • Time - GameTimer expires
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TotalPoints[1] Greater than TotalPoints[2]
          • TotalPoints[1] Greater than TotalPoints[3]
          • TotalPoints[1] Greater than TotalPoints[4]
          • TotalPoints[1] Greater than TotalPoints[5]
          • TotalPoints[1] Greater than TotalPoints[6]
          • TotalPoints[1] Greater than TotalPoints[7]
          • TotalPoints[1] Greater than TotalPoints[8]
          • TotalPoints[1] Greater than TotalPoints[9]
          • TotalPoints[1] Greater than TotalPoints[10]
          • TotalPoints[1] Greater than TotalPoints[11]
        • Then - Actions
          • Game - Display to (All players) the text: ((playerColors[1] + (RealNames[1] + colorEnd)) + has won!!!!)
          • Skip remaining actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TotalPoints[2] Greater than TotalPoints[1]
              • TotalPoints[2] Greater than TotalPoints[3]
              • TotalPoints[2] Greater than TotalPoints[4]
              • TotalPoints[2] Greater than TotalPoints[5]
              • TotalPoints[2] Greater than TotalPoints[6]
              • TotalPoints[2] Greater than TotalPoints[7]
              • TotalPoints[2] Greater than TotalPoints[8]
              • TotalPoints[2] Greater than TotalPoints[9]
              • TotalPoints[2] Greater than TotalPoints[10]
              • TotalPoints[2] Greater than TotalPoints[11]
            • Then - Actions
              • Game - Display to (All players) the text: ((playerColors[2] + (RealNames[2] + colorEnd)) + has won!!!!)
              • Skip remaining actions
            • Else - Actions
 
Last edited by a moderator:
Loop through them, and make an integer called current index.
  • CurrentIndex = 1
  • For Each (Integer A) from 1 to 12 do (Actions)
    • Loop - Actions
      • If TotalPoints[CurrentIndex] Less than TotalPoints[(Integer A)] then
        • Set CurrentIndex = (Integer A)
Whatever is left as "CurrentIndex" will be the highest score. The above code is pseudo code (just made up from my head), so you have to work it to fit GUI. You may also want to replace (Integer A) with your own iterating integer if you worry about that sort of thing.

Basically, it'll go through each index and find the highest value.

Ex: If TotalPoints[1] is less than TotalPoints[2] then it will assume the highest value is TotalPoints[2]. Then it will loop and compare TotalPoints[2] and TotalPoints[3]. Let's say that TotalPoints[2] is greater than TotalPoints[3], then that means it is still the highest value. If it is less than it, then the highest value is TotalPoints[3] (and the loop goes on to compare the rest). You don't need to check TotalPoints[1] with TotalPoints[3] now because you know:
TotalPoints[1] < TotalPoints[2] < TotalPoints[3]
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
Thanks, I tested and I think it works, but just in case I'm posting here xD

  • End
    • Events
      • Time - GameTimer expires
    • Conditions
    • Actions
      • Set CurrentIndex = 1
      • For each (Integer TempInteger) from 1 to 11, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TotalPoints[CurrentIndex] Less than TotalPoints[CurrentIndex]
            • Then - Actions
              • Set CurrentIndex = TempInteger
            • Else - Actions
      • Game - Display to (All players) the text: ((playerColors[CurrentIndex] + (RealNames[CurrentIndex] + colorEnd)) + has won!!!!)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
You keep track of the player currently winning when you increment/decrement the score. This saves you searching for the winner. You could also use an ordered list of players ordered relative to their score with 0 being highest. Both will allow you to know who won in a single line, but have varying degrees of performance and other advantages.
 
Status
Not open for further replies.
Top