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

[Tutorial] - Variables

Status
Not open for further replies.
Level 6
Joined
Apr 24, 2008
Messages
174
Variables Tutorial

Welcome to my Tutorial about Variables!
This tutorial is made for anyone who need help with Variables. The list here
is long, but also really noob-friendly, so anyone should understand what I am
teaching you :wink:

Please note that this is JUST MADE FOR VARIABLES! The examples I give
may contain leaks and such, but I only made this for the Variables sake!
Feel free to ask if you have Questions!

Ok, so lets start!


Step 1 - Getting Started

If you open your map and click F4, your Trigger Editor should open.
Now press CTRL+B to open your Variables. Now, to make an Variable,
simply click the Green Button (or press CTRL+N = New). An new window
should open where you need to type an Variable name, select an type and
check if you want Array Enabled or not.

So, just type any name you want, and select the type "Ability" and move
on to the next step in this tutorial.
Step 2 - The "Ability" Variable

Heres an example of an "Ability" variable:
  • Variables
    • Events
    • Conditions
    • Actions
      • Set Ability_Variables = Attribute Bonus
So, what does this do?
At the "Action", you Set an Variable that you have created.
To do this, create an new action and scroll down to "Set Variable".
Select the Variable you did in Step 1 and select an wanted Ability that
the variable should become!

Here is an example when this could be needed:
  • Variables
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Ability_Variables
    • Actions
The Event here is that an Unit (maby your hero or such) starts the effect
of an Ability (the unit is ordered to cast an ability), and the Condition here
uses the Variable you have done.
The (Ability being cast) Equal to "Ability_Variables" is equal to the ability
you set your variable to be. So, here you use your Variable that you have
made, to be used instead of an direct ability.
Step 3 - The "Attack Type" Variable

Here is an example of an "Attack Type" variable:
  • Variables
    • Events
    • Conditions
    • Actions
      • Set AttackType_Variable = Spells
It's the same basics here, you make an new Variable, name it whatever
you want (i named it "AttackType_Variables") and select the type or Variable
to Attack Type.
In this Action, you set your new Variable to be an Attack Type of Spells.
You can use this Variable when you order your Unit to attack another
unit, something like this:
  • Variables
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
    • Actions
      • Unit - Cause (Triggering unit) to damage (Random unit from (Units owned by Player 1 (Red))), dealing 500.00 damage of attack type AttackType_Variable and damage type Normal
So, the event here is that an Unit is ordered to attack another unit, when
it does, it will deal 500 damage, of type "AttackType_Variables", what
type is that?.... Spells! We set the Variable to be Spells, right?
This is just an example, you kinda dont need this Variable alot, but I must
teach you right? :thumbs_up:
Step 4 - The "Boolean" Variable

This is one of the most usefull Variables, so I will give alot of examples,
some may seem advanced and such, but I will explain it all for you.
Ok, so this is how an Boolean Variable looks like:
  • Variables
    • Events
    • Conditions
    • Actions
      • Set Boolean_Variables = True
It checks if something is "True" or "False". So this is what I want you to
do: Go to Variables, create a new one with any name you want and type
Boolean, and do as I will show.

We will now make an easy example of when you might need an Boolean
Variable.
So, heres what I want you to make:
1: an Event
Make it like this:
  • Variables
    • Events
      • Player - Player 1 (Red) types a chat message containing HELLO as An exact match
    • Conditions
    • Actions
The Event here is that Player 1 (Red) types "HELLO" in a message.

2: Now to the Boolean Variable, it should be like this:
  • Variables
    • Events
      • Player - Player 1 (Red) types a chat message containing HELLO as An exact match
    • Conditions
      • Boolean_Variables Equal to True
    • Actions
Ok, the Conditions here will check if your Boolean Variable is "True" or
"False", and now we will make use of this in...

3: Create an Action for this, you can make any action you want, but this
is how my example looks like:
  • Variables
    • Events
      • Player - Player 1 (Red) types a chat message containing HELLO as An exact match
    • Conditions
      • Boolean_Variables Equal to True
    • Actions
      • Game - Pause the game
So, we have now made the Game Pause if the Boolean is "True".
So, if it is "False", it will not Pause the game, you following?:cute:
We can use this for eaven more, make another Action, and set the boolean
to "False", like this:
  • Variables
    • Events
      • Player - Player 1 (Red) types a chat message containing HELLO as An exact match
    • Conditions
      • Boolean_Variables Equal to True
    • Actions
      • Game - Pause the game
      • Set Boolean_Variables = False
So, the Boolean Variable is now set to be False, so now when Player 1
types "HELLO" again, it will not Pause the Game longer, since the Boolean
is not "True", it is "False".

Here is an more advanced example of where you could need an Boolean:
  • Variables
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Boolean_Variables Equal to True
        • Then - Actions
          • Special Effect - Create a special effect at (Position of (Casting unit)) using Abilities\Spells\Human\Thunderclap\ThunderClapCaster.mdl
          • Unit - Cause (Casting unit) to damage (Random unit from (Units within 512.00 of (Position of (Casting unit)))), dealing 500.00 damage of attack type Spells and damage type Normal
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Boolean_Variables Equal to False
            • Then - Actions
              • Game - Display to (Player group((Owner of (Casting unit)))) the text: You have allready u...
            • Else - Actions
Here I use "If - Then - Else" actions, so "If" the Boolean Variable is "True",
the unit will damage another unit. "Else" (if the Boolean is False), the unit
will not damage another unit!
So basicly, when an unit uses the spell once, it cannot use it again with
dealing the bonus damage.

We could talk alot about this, but we need to move on.
If you have any Questions, feel free to ask!:thumbs_up:
Step 5 - The "Buff" Variable

Buffs can be found in most spells.
What is does, is that it gives information about the spell that an unit
is under. An example of this is Bash. When an unit gets hit by the Bash,
it will get an "buff" that says "This unit cannot move" and an icon next
to it.

Here is how it can look when you make an Buff Variable:
Variables_Buff-1.jpg


So what's done here, is that you make an Variable of type Buff.
You can also create custom buffs in the "Object Editor" (F6).
You mostly use buff Variables for things like this:
  • Variables
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Set Buff_Vairables = Aura of Blight
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) has buff Buff_Vairables) Equal to True
        • Then - Actions
          • Unit - Kill (Triggering unit)
        • Else - Actions
You can also use this Variable for Effects, that also can be created
in the Object Editor.
I WILL SOON UPDATE THIS THREAD!
 
Last edited:
Level 6
Joined
Jul 22, 2008
Messages
243
I think this is the wrong section for. Try This

Anyways. Didn't read all but, maybe you should add some kind of basic info on what a variable is?
 
Level 11
Joined
Feb 14, 2009
Messages
884
Your last example leaks and the tutorial itself is somewhat limited. It's a good start though :)
 
Level 11
Joined
Feb 14, 2009
Messages
884
Dude, read the very beginning of the thread...
This is just to show examples of Variables, I also said "I know there might
be leaks..."

I read what you wrote. I just believe that one should learn how to write efficiently from the beginning, so that he/she becomes familiar with it. I didn't mean to offend you, but if it annoys you that much, I can delete it...
 
Status
Not open for further replies.
Top