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

Basic Trigger Editor Tutorial

Level 9
Joined
Sep 5, 2007
Messages
358
Basic SC2 Trigger Editor Tutorial

Index
Let's get to the basics
Variables
Records
Functions

The Trigger Editor for the Galaxy Editor is damn powerful, it has almost unlimited features.
It will take a while before I can grasp its advanced features so I’ll share here what I’ve learned so far.

Let’s get to the basics
First off, to open the Trigger Editor click the button highlighted on the following image or just press F6.

attachment.php

You’ll see the Melee Initialization trigger, delete it.
To learn everything from scratch, we must do everything from scratch.

attachment.php

Now let’s see an overview of the main buttons of the Trigger Editor:

attachment.php

  • New Element – Creates a new thing depending on what you have selected. For example if you have a trigger selected, it will create a new trigger, if you have a comment selected, it will create a new comment. If there is nothing selected, it will create a comment by default.
  • New Folder – Creates a folder, the same thing as Categories in WE. You can use folders to better organize things like Gameplay Triggers goes to a different folder than the Spells Triggers Folder.
  • New Comment – A new comment, to write everything you want.
  • New Trigger – This creates a new trigger, where you do all the actions that affects the game itself.
  • New Condition Definition – If for example you want to create a complex condition and want to use it in several places without having to repeat it in all situations, then you can create one of this, add all the necessary conditions and then use it in the rest of the triggers (it will most likely appear in the General list of conditions)
  • New Action Definition – Similar to the Condition Definition, but with this you can make a large set of actions, and easily implement them anywhere just by using this action.
  • New Function – Action and Condition Definitions are basically functions, but with functions you have more possibilities, which will be explained later.
  • New Record – This creates a new record. A record is sort of a new variable type you create but it can have a lot of variables inside of it. For those familiar with vJass, it’s the same as Structs.
  • New Variable – Obvious, this creates a new variable. However if you click this and you don’t have a trigger selected, it will create a new global variable. However, if you have indeed a trigger selected, it will create a new local variable inside the trigger itself.
  • Test Document – This button is used to test the map.

Ok, now create a new trigger and name it “Test” or something and click on the Events/Conditions/Actions area to make available other useful buttons.

attachment.php

  • New Event – Creates a new event
  • New Condition – Creates a new condition
  • New Action – Creates a new action

Also note that you can add comments to Events, Local Variables, Conditions and Actions.

Return to Index

Variables
Variables are stuff that store stuff. A variable, depending on it’s pre-defined type, can save from numbers and strings, to units, among other things.
So you create a unit, but you want to use it later, on another trigger, well then you put that unit into the variable and then later, on the another trigger, you use that variable.

Basics of variable creation:

attachment.php

The first field Script Identifier, is mostly used when you use custom scripts. The name you gave it when creating the variable is the one you used when searching for variables to use, while the Script Identifier can have a different name but is only called from within script.

In the type list, you choose the type of variable you want it to be. The most common variable types are Integer, Real, Point, String, Unit, Unit Group, but there are so many more.

If you want to create a variable that will have a pre-defined value and won’t change during the whole game, then you check the Constant box. The variable value will be used, but won’t be able to be changed.

If you check the array box, you can have an array variable up to 4 dimensions.
You can compare an array to multiple variables of the same type.
For example you have four variables of type integer, int_var0, int_var1, int_var2 and int_var3.
Now you create an integer variable of type integer too, name it int_var.
This may seem the same, but isn’t it better to use int_var[1] or whatever, than int_var1. Using too many variables will be difficult to search for the right one since the list will get too big.

You can also define a variable an initial value.

Now to change a variable’s value, add a new action, go to the Variable category and choose Set Variable.

attachment.php

Now select the new Variable action.
Choose which variable you want to change and click on Value

attachment.php

As you can see, there are plenty of ways to change a variable.
The Function option let’s you choose a function to change the variable. It’s good if you use a function that returns a value with the same type as the variable.
For example if you use the function Math -> Arithmetic, it will return an integer variable, which is appropriate in this case.

The Variable option is used when you want a variable to have the value of another variable.

The Value option is where you set the value directly.

And the Custom Script option is where you can use script to change the variable.

Return to Index

Records
Records are basically a way for you to create your own types of variables.
For example you want to create your own Point variable, so you can do a record called MyPoint, with two real variables inside of it, one called X and the other called Y.

The process to create a record is simple, just create a new Record and add two variables. The way to create variables is the same here.

Now to create a variable of type MyPoint is a whole different matter.
Create a New Variable called point. Now for the type, you choose “– Record”, which is in the beginning of the list.
If you had more than one record, you may add to browse and choose the right record to use, in this case it won’t be necessary.

attachment.php

To change the variable values will be a bit different than normal as well.
Create a Variable -> Set Variable action.
In the Variable part you put the point variable.
In front of point, “.Member” will appear.

attachment.php

Click it to choose which variable you want to change, whether it is X or Y. Now you can set the X value for the point variable.

Return to Index

Functions

I’m putting this into one single topic because Action and Condition Definitions are derivatives of the Function itself, just with different icons.
Remember me saying that an Action Definition is something that can have a lot of actions and then you can use the action definition in anywhere else?
Functions are pretty much that.
To use functions you give them a proper name, define the return type, add up parameters if necessary, describe what the function does, if you want you can use the Custom Script Code part, add local variables if you need to, do the actions you want the function to do and then you must return a value depending on the return type you chose.

The Return type thing may be confusing at first, but it’s very useful. Let’s say you want a function that does complicated math for you but you only want the final result value. So basically you do a function with those complicated formulas and then the function returns the result directly into an appropriate variable.

The Parameters are another very useful thing. So going back to our complicated math function, let’s imagine it needs a few values in order to return the correct value, but the values wouldn’t always be the same, so you can, for instance, put parameters that when you call that function you have to put the values there.
To create a parameter, you have to click the button I’ll highlight in the next image.

attachment.php

The Hint Text is what describes the function when you select it in the functions and actions list.
The Custom Script Code is, as far as I know, an alternative to make your functions, instead of using GUI you use the Galaxy Scripting Language (GSL).
The local variables you already know what they are.
The Actions is where all calculations or actions happen in order to return the final result.

I made a simple function, it takes two points as parameters and calculates the distance between them. I know there is already a function for that, but I thought it could be a good thing for people to learn how it works.

attachment.php

For the Action and Condition definitions it’s almost the same thing, but an Action Definition don’t need to return a value unless you want it too.
I think action definitions are useful when you have a lot of actions that repeat themselves in a lot of places, so if you use those actions in an action definition and call that action definition instead, it will make the code easier to read and maintain.
The Condition definitions should always return a boolean value, either true or false, but they follow the same structure explained when using functions.


I’m sure I didn’t covered everything, but I think this should be enough to start triggering.

If something important is missing or bad explained, be sure to notice me.

Happy Triggering!

Wizzy
 

Attachments

  • Z_A.jpg
    Z_A.jpg
    38 KB · Views: 3,281
  • Z_B.png
    Z_B.png
    48.6 KB · Views: 3,543
  • Z_C.jpg
    Z_C.jpg
    67.5 KB · Views: 3,690
  • Z_D.png
    Z_D.png
    48.2 KB · Views: 3,235
  • Z_E.jpg
    Z_E.jpg
    48 KB · Views: 3,230
  • Z_F.jpg
    Z_F.jpg
    54 KB · Views: 3,177
  • Z_G.jpg
    Z_G.jpg
    87.3 KB · Views: 3,174
  • Z_H.jpg
    Z_H.jpg
    71.6 KB · Views: 3,180
  • Z_I.jpg
    Z_I.jpg
    22.9 KB · Views: 3,147
  • Z_J.png
    Z_J.png
    5.5 KB · Views: 3,186
  • Z_K.png
    Z_K.png
    13.1 KB · Views: 3,153
Last edited by a moderator:
Level 18
Joined
Aug 23, 2008
Messages
2,319
Great job! Very informative, but you might want to add how to exactly implement Functions (even though you'd only have to say it's just like Records, but instead of using it in a Variable, you use it as a value)

You also forgot about Preset Types/Values and Sub-Function Types. If you could add some info about that, I'd say this is a wonderful and complete tutorial :thumbs_up:
 
Level 11
Joined
Aug 1, 2009
Messages
963
New Record – This creates a new record. A record is sort of a new variable type you create but it can have a lot of variables inside of it. For those familiar with vJass, it’s the same as Structs.
No, it isn't the same.

You can't use them as parameters for functions, which kinda ruins the point.
 
Level 18
Joined
Aug 23, 2008
Messages
2,319
Besides from the fact that you resized that image way too much for any detail, I think I can safely say that you probably have the retail version of SC2. They might have a slightly different UI setup for the editor then the BETA editor which was used for this tutorial.

Or maybe you got a later version of the BETA editor. This tut was made during 1 of the earlier versions.
 
Very nice tutorial, very glad it was made, one request, could you perhaps use a weak trigger as an example to explain your princibels? like a weak zergling mass spawn mixed with teleportations or somthing, i still dont truely under stand what paramaters are, im somwhat aware of the wc3 editor, as well as the old sc editor, not that either of those editors compare with this, so paramaters confuse me.

just a request for extra explanation.
 
Level 2
Joined
Feb 17, 2008
Messages
13
I'm glad Blizzard made triggers more like actual programming rather then "advanced" if-else functions. And Parameters are like... if you've taken Algebra II and you know what a function is, like for example f(x): x*12/6. then "x" is the "parameter" of the function... basically you make your complex formula and whereever you have a value that might change everytime you do the formula, (a non-constant) you would replace it with your parameter. so for example E=CM^2, C is a constant for speed of light, but M for mass isn't, everything has a different mass, so you would plug "x" in for Mass. when you call the function you replace X with the number you want to equal the mass. You can add multiple parameters also so you could have "myFunction(x, y)" and x and y are parameters. (ignore that coding, it was just an example) And parameters don't always have to be numbers, they are basically local variables that exist only as long as the function is running and are then deleted from the memory.
 
Top