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

[Trigger] Random Hero Problem

Status
Not open for further replies.
Level 2
Joined
Jan 7, 2013
Messages
13



IMG2

This code supose to make a random hero, but it doens't.Every time it's get exactly the same number and same hero.I do no what to do,
Thanks At All,
Jamal XVI
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
@Maker
By using that algorithm, ain't that method disturbs the original order of the array (not that this does not appeal to the thread's topic) ?

Let's say we have 5 values from a single array;
Number[1] = 1
Number[2] = 2
...
Number[5] = 5

The order would be: 1, 2, 3, 4, 5.

Let's take your algorithm into actions and let's say the random is 3, therefore;
Number[3] is 3, right ?

Then;
Number[3] = Number[5] (since 5 is the max)

The order now would be;
1, 2, 5, 4, 5.

Then;
Max = Max - 1

The order now would be;
1, 2, 5, 4.

Is this the correct tracing of values, right ?
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
@Starquizer, using the method I posted, it could be as simple as this. Your method does unnecessary loops.

  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • -------- -------------------------------------------------- --------
      • -------- Initializes desired numbers --------
      • -------- -------------------------------------------------- --------
      • For each (Integer A) from 1 to 16, do (Actions)
        • Loop - Actions
          • Set itaken[((Integer A) + 16)] = (Integer A)
      • -------- -------------------------------------------------- --------
      • -------- Randomizes the order of numbers --------
      • -------- -------------------------------------------------- --------
      • For each (Integer A) from 1 to 16, do (Actions)
        • Loop - Actions
          • Set i = (Random integer number between (Integer A) and 16)
          • Set itaken[(Integer A)] = itaken[(i + 16)]
          • Set itaken[(i + 16)] = itaken[((Integer A) + 16)]
      • -------- -------------------------------------------------- --------
      • -------- Prints the numbers --------
      • -------- -------------------------------------------------- --------
      • For each (Integer A) from 1 to 16, do (Actions)
        • Loop - Actions
          • Game - Display to Player Group - Player 1 (Red) for 30.00 seconds the text: (String(itaken[(Integer A)]))
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I just want to share to you guys how to remove an element from an array without disturbing its order (but I guess it won't be used in this case - since order does not matter in your case - perhaps some other time ?)

  • Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Number[1] = 1
      • Set Number[2] = 2
      • Set Number[3] = 3
      • Set Number[4] = 4
      • Set Number[5] = 5
      • Set Max = 5
  • Remove Element
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set Random = (Random integer number between 1 and Max)
      • Game - Display to (All players) the text: (|cffffcc00 + ((String(Random)) + |r))
      • Set Max = (Max - 1)
      • For each (Integer LoopingInteger) from Random to Max, do (Actions)
        • Loop - Actions
          • Set Number[LoopingInteger] = Number[(LoopingInteger + 1)]
      • For each (Integer LoopingInteger) from 1 to Max, do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: (String(Number[LoopingInteger]))
This will remove an element from an array without disturbing its order.
 
Last edited:
Level 2
Joined
Jan 7, 2013
Messages
13
Solved

@HesitationSnow
This is My problem!Thanks at all!
@Maker && @defskull && @Starquizer
The solutions you proposed are exelent, may i change my system.Thanks at all!


+Rep all you guys
 
Status
Not open for further replies.
Top