• 🏆 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!

Pick a Random Integer

Level 2
Joined
Dec 11, 2010
Messages
4
How to Use "Pick a Random Integer"


You may have seen this option in GUI before. Maybe that's why you viewed this tutorial. It appears in Math, and it is called Random Number.

With this function, you can have random events, numbers, or rewards(you can use something else for this) appearing in your map.

To use this function, you must have a variable, which can be created at the Variable Editor. The variable must be an INTEGER.

After completing the task, you may proceed to step 1.

Step 1

Create the desired event. For this tutorial, we will use Time - Periodic Event.

  • Random Integer
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
You may also add a condition. If you want.

Step 2

Now set the variable. We will use E1 for the tutorial.

  • Random Integer
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Set E1 = (Random integer number between 1 and 2)
Once that is done, we will go to the tricky part.

Step 3

Now, you must create actions corresponding to the picked integers.

Create a new ACTION, then choose If Then Else Multiple Functions.

The "Then" will be the action corresponding to 1.

We will use "Hello World" as the "Then" for 1.

  • Random Integer
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Set E1 = (Random integer number between 1 and 2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • E1 Equal to 1
        • Then - Actions
          • Game - Display to (All players) the text: Hello World!
        • Else - Actions
For the integer 2, we will repeat these steps.

For this tutorial, we will use Hello Azeroth!

Since we are done with the trigger, put Do Nothing on the last Else.

The finished trigger will look like this:

  • Random Integer
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Set E1 = (Random integer number between 1 and 2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • E1 Equal to 1
        • Then - Actions
          • Game - Display to (All players) the text: Hello World!
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • E1 Equal to 2
            • Then - Actions
              • Game - Display to (All players) the text: Hello Azeroth!
            • Else - Actions
              • Do nothing
Before you test out the map, go to File > Preferences > Test Map and disable Use Fixed Random Seed
Go check out the map, to see if you really got it right.
---------------------------------------
Have fun with random integers!
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
This is how you should do the triggers:


50% chance to do something:
  • Random Integer
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 2) Equal to 1
        • Then - Actions
          • Game - Display to (All players) the text: Hello World!
        • Else - Actions
50%/50% chance:
  • Random Integer
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 2) Equal to 1
        • Then - Actions
          • Game - Display to (All players) the text: Hello World!
        • Else - Actions
          • Game - Display to (All players) the text: Hello Azeroth!

  • Random Integer
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Set E1 = (Random integer number between 1 and 3)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • E1 Equal to 1
        • Then - Actions
          • Game - Display to (All players) the text: Hello World!
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • E1 Equal to 2
            • Then - Actions
              • Game - Display to (All players) the text: Hello Azeroth!
            • Else - Actions
              • Game - Display to (All players) the text: It was the third option
This is quite simple tutorial, and might not need a tutorial at all.
 
Last edited:
Maker, your third trigger doesn't even make sense. The last else block can never be reached.
I think, that it can be reached.

E1 can be 1 or 2 or 3 right,
JASS:
if E1 equal to  1 then
//xxxx
elseif E1 equal to 2 then
//xxxx
else (Where we check is E1 equal to 3 or any other number except 1 and 2)
//xxx
endif

Jass tags to make this look like code.
 
Top