Hello there! We are conducting a survey to better understand the user experience in making a first edit. If you have ever made an edit on Gamepedia, please fill out the survey. Thank you!
Tutorials/Willu's Guide To The Trigger Editor
- 1 Willuwontu's Guide to the Trigger Editor
- 2 Part 1: The basics
- 2.1 Overview of the Trigger Editor
- 2.2 Basics of creating Triggers (AKA what this editor is all about)
- 2.2.1 Triggers
- 2.2.2 Variables
- 2.2.3 Actions
- 2.2.4 Functions
- 2.2.5 Conditions
- 2.2.6 Events
- 2.3 Basic Actions
- 2.4 Basic Functions
- 2.5 Basic Events
- 3 Part 2: Intermediate Concepts
- 4 Part 3: Advanced Concepts
Willuwontu's Guide to the Trigger Editor
Part 1: The basics
Overview of the Trigger Editor
The trigger editor was created by Blizzard in order to assist mapmakers/modders in creating dynamic events as the game progressed, unlike the data editor which can only influence the data at the start of the game.
This allows checkpoints to be created in an RPG, spawning of special minions in MOBA's, and wave spawning in Tower defense games.
Basics of creating Triggers (AKA what this editor is all about)
Triggers are the fundamental concept of the trigger editor. They function by receiving inputs from in-game events, and then run a series of actions.
A newly made Trigger looks like this Under the name of the trigger it lists what events cause the trigger to run, what variables it contains within it, what conditions must be met when the event is activated, and what actions this trigger will perform.
Variables are information that is stored for later access. Every variable must be assigned a data type. A variable may only store information appropriate for it's type. In other words, integer variables can only store integers, and unit variables can only store units. These are the most commonly used part of the trigger editor.
When a variables is created created it can either have a Global Scope or a Local Scope.
An action is what the trigger will do when it runs (Ex: Destroys all units, give a player money, etc.)
Functions take a set of inputs (parameters) and return a value based upon them, the data type of the returned value is the data type of the function.
A function selection pops up when the parameters of an action, event, or condition is clicked on, bringing up a screen for data input.
A condition is almost exactly the same as a function except it only returns a boolean value (True or false). Conditions are used to evaluate whether a trigger will run when it's event is met of not, and also evaluate which branch of an If-then-Else action to take (If true do this, else do this). By default all conditions must be true in order for it to run.
This condition compares a values of the same data type against each other and returns true or false based on the comparison operators used.
==: Returns true if both are the same
!=: Returns true if they are different
>=: Returns true if one value is greater than or the same as the other (only used by numerical comparisons)
<=: Returns true if one value is less than or the same as the other (only used by numerical comparisons)
>: Returns true if one value is greater than the other (only used by numerical comparisons)
<: Returns true if one value is less than the other (only used by numerical comparisons)
Conditions are able to be nested as depicted in the pictures above. This results values being evaluated from the bottom up (Ex: if you have an OR condition inside of an AND the And condition only cares about whether the OR condition returns True and not the conditions inside of the OR).
Events are used in starcraft 2 to initiate a trigger. When the event occurs in the game, the trigger will run, as long as all the conditions are valid.
When modifying a selected event you can click on different colored parts of it to bring up a list of functions and variables for the required data type. When doing so, you must not use a variable, because doing so will result in the event not functioning properly.
Set Variable = Value
Sets a variable to some value
Set Number of units = (Count of Any units in (Entire map) owned by player Any Player matching Excluded: Missile, Dead, Hidden, with at most Any Amount)
If THen Else
Then do actions
Else do actions
If the condition is true, do some action If the condition is false, do some action instead
If (Count of Any units in (Entire map) owned by player 1 matching Excluded: Missile, Dead, Hidden, with at most Any Amount) >= 5
Then do Kill all units
Else do nothing
End Game for Player
End game in Game over type for player Value (Show/hide dialogs,Show/hide score screen.
Ends a game for a player in victory, defeat or a tie. It then shows the quit/continue playing dialog and hte score screen after they exit the game, depending on your choice. Typically used with events to determine when certain objectives are met, such as a player losing all their units, or having held a point for a certain length of time and ending the game for them.
End game in Defeat for player 1 (Hide dialogs,Show score screen.
Value Arithmetic Operator Value
Does math with 2 numbers.
Set Life = Life - 5
Runs the trigger when the map is loading
Runs the trigger when a unit dies
Any Unit dies
Unit type of (triggering unit) == hero
Wait 30 seconds
Revive (Triggering Unit)
Part 2: Intermediate Concepts
In part 1 we cover how variables are stored values of a certain datatype, in a similar fashion Arrays are able to hold multiple values of the same data type. This means instead of creating a bunch of variables named player 1 unit, player 2 unit, etc, you can create one array called playerUnits
If you notice the  at the end of the array there, that determines the size of the array or how many different pieces of data A visual comparison of data storage is something like this.
|Element #||Array Value||Variable Value|
As you can see arrays can hold far more data than a single variable. You also may have noticed the Element # header in the table there under array. Each value an array holds is assigned an element # to show its position of where it is stored in the array. Arrays are 0-based, this means that the first element of an array is 0, this also means that the last element of an array is its size - 1, however blizzard automatically adds 1 to the size of an array created in the GUI editor since many people kept trying to access an element = size of the array.
In addition to arrays being able to hold multiple values, they can also be made up of multiple dimensions or element columns this is what an array of size  looks like.
|Element #||Array Value|
|Element #||Array Value|
For each element in the first column, it can store 3 more values from the second column, increasing the amount of values able to be stored as well.
Similar to arrays records are able to hold various values, however unlike arrays these values do not have to be of the same data type. How this work is a record is essentially association of a group of variables or arrays.
When you create the record you declare what variable you hold in it, an example of this would be a record for usage in a dialog where clicking a button causes the player to be upgraded. These variables are then considered members of the record, accessed within a variable of the record type.
In this case you would have a record that looks like this
|Member Name||Member Datatype||Member Value|
|Button||Dialog Item||Some Dialog Item|
|Maximum Amount||Integer||Some amount|
What this does is it creates a template for calling on using other variables which are created as instances of the record.
You would then create a variable of that records type in order to access the members of it.
After creating it you would access the members and set them
Set UpButton.Button to (last created dialog item)