Tutorials/Willu's Guide To The Trigger Editor

From SC2Mapster Wiki
Jump to: navigation, search

Willuwontu's Guide to the Trigger Editor[edit | edit source]

W.I.P.

Part 1: The basics[edit | edit source]

Overview of the Trigger Editor[edit | edit source]

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)[edit | edit source]

Triggers[edit | edit source]


Overview[edit | edit source]

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.

Usage[edit | edit source]

You create a new trigger by clicking this Icon Create new Trigger Icon.JPG or pressing CTRL+T.

A newly made Trigger looks like this New Trigger.jpg 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[edit | edit source]


Overview[edit | edit source]

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.

Usage[edit | edit source]

Variables are created by clicking this icon Create New variable Icon.JPG or pressing CTRL+B

When a variables is created created it can either have a Global Scope or a Local Scope.

A global scope variable is created outside of a trigger Global Scope.JPG and is usable by all triggers. A local scope variable is created inside a trigger Local Scope.JPG and is usable by that trigger only.

Actions[edit | edit source]


Overview[edit | edit source]

An action is what the trigger will do when it runs (Ex: Destroys all units, give a player money, etc.)

Usage[edit | edit source]

An action can be created by clicking this icon Create new Action Icon.JPG or pressing CTRL+R inside a trigger.

This opens up a selection of actions to choose from New action Selection.JPG, selecting an action and clicking "Ok" adds that action to the triggerNew Action.JPG.

It is then possible to modify what that action does by clicking the highlighted portions of it Modify Action Parameters.JPG, and inputting data, variables, or functions of the correct datatype.

Functions[edit | edit source]


Overview[edit | edit source]

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.

Usage[edit | edit source]

A function selection pops up when the parameters of an action, event, or condition is clicked on, bringing up a screen for data input.

By clicking on the function tab a selection of functions of the relevant data type appears Function selection.JPG. You can select one and click "OK" to use it to generate a value for the parameter.

Conditions[edit | edit source]


Overview[edit | edit source]

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.

Usage[edit | edit source]

You can add a new condition to a trigger by clicking this Icon Add new Condition Icon.JPG or pressing CTRL+K.

This will bring up the condition selection menu Condition Selection.JPG, in the menu there are 6 Choices, 5 of which I'll go over.
Selecting any of them and clicking "Ok" results in a new condition appearing New Condition.JPG

Comparison:[edit | edit source]

Comparison Condition.JPG
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)

Within Bounds:[edit | edit source]

Within Bounds Condition.JPG
This condition compares a number value against 2 others and returns true if it is between the 2.

And:[edit | edit source]

And Condition.JPG
This condition takes any other conditions under it and returns True only if they are all true

Or:[edit | edit source]

Or Condition.JPG
This condition takes any other conditions under it and returns True if any condition is true

Not:[edit | edit source]

Not Condition.JPG
This condition takes any other conditions under it and returns True only if they are all False

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[edit | edit source]


Overview[edit | edit source]

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.

Usage[edit | edit source]

An event is created by clicking this icon Create New Event Icon.JPG or pressing CTRL+E while inside a trigger

This opens up a selection of events for usage New event selection.JPG, selecting a choice and clicking "Ok" adds that event to the triggerNew Event.JPG.

When modifying a selected event you can click on different colored parts of it Modifying an event.JPG 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.

Basic Actions[edit | edit source]

Set Variable[edit | edit source]


Syntax[edit | edit source]

Set Variable = Value

Usage[edit | edit source]

Sets a variable to some value

Example[edit | edit source]

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[edit | edit source]


Syntax[edit | edit source]

If Condition
Then do actions
Else do actions

Usage[edit | edit source]

If the condition is true, do some action If the condition is false, do some action instead

Example[edit | edit source]

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[edit | edit source]


Syntax[edit | edit source]

End game in Game over type for player Value (Show/hide dialogs,Show/hide score screen.

Usage[edit | edit source]

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.

Example[edit | edit source]

End game in Defeat for player 1 (Hide dialogs,Show score screen.

Basic Functions[edit | edit source]

Arithmetic[edit | edit source]


Syntax[edit | edit source]

Value Arithmetic Operator Value

Usage[edit | edit source]

Does math with 2 numbers.

Example[edit | edit source]

Set Life = Life - 5

Basic Events[edit | edit source]

Map Initialization[edit | edit source]


Syntax[edit | edit source]

Map Initialization

Usage[edit | edit source]

Runs the trigger when the map is loading

Unit Dies[edit | edit source]


Syntax[edit | edit source]

Unit dies

Usage[edit | edit source]

Runs the trigger when a unit dies

Example[edit | edit source]

Event:
Any Unit dies
Condition:
Unit type of (triggering unit) == hero
Actions:
Wait 30 seconds
Revive (Triggering Unit)

Part 2: Intermediate Concepts[edit | edit source]

Arrays[edit | edit source]

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[12]

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.

Array Variable
Element # Array Value Variable Value
0 Value Value
1 Value
2 Value
3 Value
4 Value
5 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 [3][3] looks like.

Array
Element # Array Value
Element # Array Value
0 0 Value
1 Value
2 Value
1 0 Value
1 Value
2 Value
2 0 Value
1 Value
2 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.

Records[edit | edit source]

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

UpgradeButtonRecord
Member Name Member Datatype Member Value
Button Dialog Item Some Dialog Item
Upgrade Upgrade Some Upgrade
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.

UpgradeButtonRecord UpButton

After creating it you would access the members and set them

Set UpButton.Button to (last created dialog item)

Presets[edit | edit source]

Custom Actions[edit | edit source]

Custom Functions[edit | edit source]

Part 3: Advanced Concepts[edit | edit source]

Dynamic Events[edit | edit source]

Data Type Conversions[edit | edit source]