• 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.

Random colours - (more inside)

Status
Not open for further replies.
Level 5
Joined
Jul 17, 2013
Messages
128
Hello, i need to randomize colours of players, but there cannot be any 2 players that have same colour. Can somebody post there GUI trigger for it? because i dont really know how to check if some other player have same colour and change it to other.
 
Level 5
Joined
Jul 17, 2013
Messages
128
Hello, we are in Triggers section... I want to randomize colours of players that red will never have red colour etc. and YES i want to include unit colour change but with trigger not in editor mate :)
 
Level 5
Joined
Jul 17, 2013
Messages
128
1. Add all colours to a playercolor list.
2. Get random element of list.
3. Remove element from 2 from the list.
4. Set player color to element from 2.
5. Repeat from step 2 until all players have a color.

1. I understand - already have
2. What random element? How to make
3. undestand but how implement that element
4. kinda ok
5. run again trigger...
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
2. What random element? How to make
If an array list is used, then a simple random index within the array list will work.

Eg...
List contains 3 colors. We want a random one.
colors[0] = Red
colors[1] = Green
colors[2] = Blue

We choose a random index by getting a random integer in the range of 0 to 2 inclusive (there is a native/GUI function that does this). We then use that random number as an index for the array. Obviously store it to a local / locally used global as we cannot "recomputed" a random number.

For the rest of this post I assume you have computed this random number and it rolled 1.
RandomIndex = 1

3. undestand but how implement that element
Using a local or locally used global as described above. You then replace that index with the maximum index value and decrement the size of the array list (discarding the maximum value).

Eg.

Initial condition
colors[0] = Red
colors[1] = Green
colors[2] = Blue
ColorsMax = 3

RandomIndex = random integer between 0 and (ColorsMax - 1)
RandomIndex = 1 (this was the result of above)

color = colors[RandomIndex] // We need this later
ColorsMax = ColorsMax - 1
colors[RandomIndex] = colors[ColorsMax]

After this has run the list looks as such...
colors[0] = Red
colors[1] = Blue
ColorsMax = 2

4. kinda ok
Just set the player's color to color (computed as described above).

5. run again trigger...
Or call the function again, or loop again. Depends on how you want to implement it.
 
Level 5
Joined
Jul 17, 2013
Messages
128
What i did wrong?
 

Attachments

  • (12)DivideAndConquer.wtg
    3.3 KB · Views: 30

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
What i did wrong?
You posted your trigger as a wtg file instead of in a readable form.

As for the triggers themselves once I opened WorldEdit...

  • init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Colours --------
      • Set ColourNumber = 0
      • Set Colour[(ColourNumber + 1)] = Red
      • Set Colour[(ColourNumber + 1)] = Blue
      • Set Colour[(ColourNumber + 1)] = Teal
      • Set Colour[(ColourNumber + 1)] = Purple
      • Set Colour[(ColourNumber + 1)] = Yellow
      • Set Colour[(ColourNumber + 1)] = Orange
      • Set Colour[(ColourNumber + 1)] = Green
      • Set Colour[(ColourNumber + 1)] = Pink
      • Set Colour[(ColourNumber + 1)] = Gray
      • Set Colour[(ColourNumber + 1)] = Light Blue
      • Set Colour[(ColourNumber + 1)] = Dark Green
      • Set Colour[(ColourNumber + 1)] = Brown
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set RandomIndex = (Random integer number between 1 and ColoursMax)
          • Set Color = Colour[RandomIndex]
          • Set ColoursMax = (ColoursMax - 1)
          • Set Colour[RandomIndex] = Colour[ColoursMax]
          • Player - Change color of (Picked player) to Colour[RandomIndex], Changing color of existing units
I do not see how you could ever expect this to work. Firstly you only set index 1 to Brown (hardly an array list of all colors). Secondly you never initialized ColorMax to a meaningful value.

JASS has no "++" operation (atomic evaluate and pre/post increment). You need to increment the variable afterwards implicitly.

You may have more luck with this...
  • init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Colours --------
      • Set ColourNumber = 0
      • Set Colour[ColourNumber] = Red
      • Set ColourNumber = (ColourNumber + 1)
      • Set Colour[ColourNumber] = Blue
      • Set ColourNumber = (ColourNumber + 1)
      • Set Colour[ColourNumber] = Teal
      • Set ColourNumber = (ColourNumber + 1)
      • Set Colour[ColourNumber] = Purple
      • Set ColourNumber = (ColourNumber + 1)
      • Set Colour[ColourNumber] = Yellow
      • Set ColourNumber = (ColourNumber + 1)
      • Set Colour[ColourNumber] = Orange
      • Set ColourNumber = (ColourNumber + 1)
      • Set Colour[ColourNumber] = Green
      • Set ColourNumber = (ColourNumber + 1)
      • Set Colour[ColourNumber] = Pink
      • Set ColourNumber = (ColourNumber + 1)
      • Set Colour[ColourNumber] = Gray
      • Set ColourNumber = (ColourNumber + 1)
      • Set Colour[ColourNumber] = Light Blue
      • Set ColourNumber = (ColourNumber + 1)
      • Set Colour[ColourNumber] = Dark Green
      • Set ColourNumber = (ColourNumber + 1)
      • Set Colour[ColourNumber] = Brown
      • Set ColourNumber = (ColourNumber + 1)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set RandomIndex = (Random integer number between 0 and (ColourNumber - 1))
          • Set Color = Colour[RandomIndex]
          • Set ColourNumber = (ColourNumber - 1)
          • Set Colour[RandomIndex] = Colour[ColourNumber]
          • Player - Change color of (Picked player) to Color, Changing color of existing units
 
Status
Not open for further replies.
Top