In this guide it will teach you the knowledge base you will need to start making your own complex triggers and functions. the guide is meant to be done from start to finish, i try to explain everything in detail as i am doing it so you are not just a robot going through the motions and you learn and understand from what you are doing as you follow through.
The Guide will do a whole bunch of un-necessary Stuff to create 1 zergling for you when the map starts. but its the un-necessary stuff that is going to teach you how to use the basic functions of the trigger editor.
First off is variables and understanding how they work. This is crucial to any map making. You will use this for almost every trigger you create in the trigger editor. Variables are good for moving information around and storing information.
A variable stores information that you want for later use. understanding the different types of variables is essential to using triggers. there are:
Local Variables are variables that can only be used in the trigger that you are currently using. first is to create a new map and go into the Terrain editor. on the toolbar click on "Layer" and select the points layer. Create a point anywhere and name it whatever you want. we will need this later.
To create a new local variable, go to the trigger editor, the map initialization trigger and delete all of the items under "actions". then right click in the trigger window go to new then select variable:
Then name your variable. This can be anything you want. name it something that describes what information it's going to hold or something you can remember later: im going to name mine Players number.
After you enter your name you will notice variable type. Now here is where you have to tell the Variable what kind of information is going to be stored in it.
I'll touch on some basic types and what they are:
Integer: Whole Numbers (ie 1, 2, 3, 4, 5), used to keep count, player numbers 0-15, do math functions used to keep track of arrays. if a Real is converted to a Integer it keeps it's decimal places.
Real: Number with decimal places (ic 1.2, 3.5, 5.7), Used in units health, time, points(locations), Unit and Camera rotation. a integer can be converted to a real.
String: Text with several words in it, or even a single word. with the string you can store things like any inputted text from the user. you can convert text to strung and vice/versa. With the string type you can do all kinds of neat tricks find and replace words, remove words, ect. used to store most text in the editor.
Text: Stores as raw text. Used in most triggers for tool tips and labels. can manipulated with fonts and font colors, bold ect...
Unit: this stores a Specific unit. used if you want to get health, energy or any stats from a unit, or interact with the chosen unit in any way.
Unit Type: This is a generalized unit, a game link. used for creating units or checking a units unit type (what unit a unit actually is)
It's important to know the difference between unit and unit type because they are 2 different things. if you want to kill a specific unit off, move a unit, get a location of a unit you would use 'unit' as the variable type. If you wanted to Create a new unit you would use unit type.
Dialog: Stores a Specific dialog box, you would use this a lot if you where creating a custom UI, it is used to identify where to put dialog items, showing and hiding the dialog box, and destroying the dialog box.
Dialog item: A dialog item is a item such as a label or a button or a picture that gets places within a specified dialog. This type of variable is most commonly used for destroying and re-creating Dialog items to "update" their information such as a health bar a constant changing number ect.. the editor does not update these items in real time so the dialog items must be destroyed and re-created.
Boolean - This is simply True/False. Has tons of uses when checking for conditions in a if statement or the trigger conditions.
For this purpose we will leave it integer.
now we will set our variable. as noted above a integer stores a number to let put a number into our variable. first right click go to new, then select action:
now set variable should be the default one selected if it's not of the left in the label column find variable category select it and then select "Set Variable" and hit ok.
Now at the bottom click on the hyper-linked word "Variable" a list will pop up.
Select the variable that you created earlier and click ok. you will notice that the hyper-linked word "Variable" has changed to your variable name. this is why i asked you to make the name descriptive of what it is going to hold in it. now click the "Value" Hyperlink
A box will appear you will see a "Value" input box enter 5 into the box and press ok.
Congratulations! you have created and stored in a variable it is that easy! now that we have a variable and information in it, lets use that information.
What is a global variable? A global Variable is a variable that can store information and pass it between any trigger or function. It is not restricted to a trigger or function like a local variable.
why even have local variables then? separating these are important for a number of reasons, the list when you go to select a variable will be huge, naming will become a problem, the amount of system memory being used will go up (a little) and sometimes you just need that variable for the trigger and you do not need to carry the information anywhere else.
Creating a Global Variable:
Right click on the left pane where your triggers are. go to new and select variable.
Name the variable Global Player (again, this can be named anything you want) keep the variable type integer.
Now create a new trigger. name it whatever you like, i am going to name mine "math"
Now in your new trigger create a new variable and name it New number and keep it integer. then create a new action to set a variable. Click on the Hyper-linked word variable and a pop-up will appear. here you see 2 variables now, note the right column where it says source you will see Global and local. Select the global variable that you created and press ok.
now click on the Hyper-link work value and a pop-up will appear, in this pop up first select function
Then go to math and select Arithmetic and click ok (basic math is fun!)
now the Hyper-link work value has gone away and has been replaced by "(Value 1 + 1)" now everything in the parentheses can be changed including the + to change the math function (i.e. /, *, -) for now click on "Value 1" and select Variable at the top. (please note the type greyed out as seen here. this will tell you what type of information the field you clicked on is looking for.) new select new number variable (the local one you created) and press ok.
now click on the "1" at the bottom and change that to 7 and then click on the "+" and when the pop up comes up select the "-" and press ok you should have something that looks like this:
Nice. You have now set your Global Variable! let's create more information to use our new local and global variables.
Constants are variables that cannot be set and can not change. Why would you use a constant? To label your variable in the case of this guide we will be labeling a number to identify the meaning of the number so when you look at your trigger months down the road it will give you some incite into what the number is for and wont show for example the number "2". It is also useful for if you are going to be using the variable in many places and want to use it as a key or identifier of a static or constant variable.
Using constant variables
To pick up where we left off click on your math trigger and locate the local variable you created in it earlier and click on that local variable. now on the bottom pane check of the constant box. Then click on the 0 and set it to 2.
That's all you have to do to set a constant. seance we used this variable already in our arithmetic math function that's all we will be doing with it for now. keep this open will will continue using it after this lesson on arrays:
An array is a variable with indexes the indexes reference where your information is stored in the array. an array in the trigger editor is a variable followed by numbers in brackets, ie. MyVariableName this array can hold 18 variables. each number is a index to the number in the previous bracket. understand?
How dose the array work? Arrays, the easiest way to explain a array is by picture:
Arrays are VERY powerful. they can hold a lot of information in a single variable. how do you use it? what way could it be useful? indexing eliminates the need to create several variable that do the same thing. for example:
i have a RPG map and i have 10 players playing and each player has a hero. without arrays i would have to create 10 variables that look something along the lines of this:
Players hero 1<unit>
Players hero 2<unit>
Players hero 3<unit>
Players hero 4<unit>
with an array i can turn all 10 of those into:
Players hero  <unit>
use the players "player number" (ie player 1 would be 1, player 2 would be 2, ect. whenever you call triggering player or picked player of some kind it will return their player number in a integer field.) to index where the hero in the array and where it is kept. the  is a integer. so you can stick a variable or a constant in the brackets with the variable type integer and it will look in the index based on that number.
now that you have a rough idea as to what an array is lets continue the tutorial and create a basic array.
Now Create a new Global variable. name it "Player Hero". now for the variable type we are going to select "Unit" from the drop-down.
now click the array check-box and set the array size to 10.
Now create another global variable. name it "Hero" set the type to "unit type"
Click on the "No Game Link" on the bottom right. Click the value button, make sure the drop-downs say "all" then search for zergling and select it.
We are going to pause for a moment here to learn about creating a custom function. we will set our array after.
Creating a Function
This is what most people seem to be confused about so i am going to take some time to explain what a function is and how to create one. Why use a function? have you ever created and set its image or hover image. and done this for every button you created? dont you wish you had some way just to have all those actions in one? well with functions you can. you can do everything from get a units positions, to Dialogs really. here is an example of how i created a custom function.
A function is pretty much anything you can call from a trigger.
here is the function UI i will explain what each piece does:
First the "Options" Drop-down:
If you look at an empty trigger all these categories will be on there with the exception of Functions. once your function is created if you add a action, event, or condition your function can be found under general. the same is true for Functions.
Events - Initiates a Trigger - the actions in this function have been done it initiates the trigger.
Actions - Runs any actions that are under the actions within the functions
Conditions - I have not even found a use for this.
Functions - Functions will appear with other functions (like the arithmetic function under math for integer that we used earlier) based on the return type ie (integer, unit, Real, ect)
Only Functions require a return type. Actions, Conditions and Events do not you can simply set this to none.
Return Type: when a Functions return type is set this is what type of information will be returned back to the trigger. for example lets look back at our math trigger and look at where we set our global variable. I clicked on "New Number" then selected functions and then the general category. note the type. if you set your return type to integer it will match the type of field you want it to go to like our integer global variable. all custom functions will always be in the general category.
IF YOU HAVE A RETURN TYPE OTHER THAN "NONE" YOU MUST HAVE THE ACTION
"value"s type is based off your return type. so if your return type is integer "Value" will be a Integer field. this action will return the value back to the trigger. you may only have 1 return value action.
Parameters: Parameters are inputs from the function. an good example of this is the "create unit" function. when you select the function action of creating a unit the hyper-linked text will appear, and that is your parameters. they are bits of information being passed from the trigger to the function. If you need the player number create a Parameter named "Player" set the parameter type to integer and the word "Player" will appear in the trigger hyper linked, allowing you click on it and get the pop up box asking you for some kind of integer.
Now using parameters in your function is simple. say if you have a action that requires a integer (a player number), and your input box comes up to set your integer just click on parameter and your "Player" parameter will be listed here.
This allows that "Player" parameter information to be passed from the trigger to the actions in your function.
Grammar Text: this is what you see in the trigger in that bottom pane where the hyperlink information is. you can make this whatever you want. i usually don't set it but you can if other people will be editing your map so they know whats going on with the parameters. here is an example of the Grammar pane, you can type it out the same to look like English in the trigger:
Hint text: is below the Grammar pane above. you can make this anything.
Custom Script Code: Self explanatory. if you want to custom script Galaxy code in. for programmers.
Local Variables: Variables that are specific for this function.
Actions: preform the actions of the function with the information gathered and based off of your parameters and return type.
ok schools over back to the tutorial!
Creating a function:
So first step is to create a new function right click in the trigger pane on the left. Select New -> Function and name it "player gets unit".
Next set the Options drop-down to "Action" and the return type to "None"
Now create a new parameter and name it 'Player' keep the Type integer.
Create a local variable and name it "player number" keep its type to integer.
Now we want to set the variable so right click in the the function pane somewhere and select new -> action, Set variable.
we are getting the local variable that we just created "Player number"
now click on the hyper-linked "Value" go to math category and arithmetic (multiple) and click ok.
Now we must add to the arithmetic function 3 times this is done by right clicking in the function frame on top of the "values<integer+>"
you need to create one for:
the value of 1
the parameter "Player"
and the Global variable "Global Player"
Should look like this when you add all 3:
Then create a new action, right click somewhere in the function pane go to new -> action when the window pops up go to general and select if than else then press ok.
at this point your function should look like this:
now we need to add a condition to our "IF" so right click on "IF" and select new condition. the default is comparison so it will be highlighted. click ok:
In the function frame double click on value 1 a window will appear. click on variables on the top and select your local variable. click ok. when you click ok the == should be 1.
Click on the word "Then" on the "If" statement right click on it and go to new action create unit with no default facing then click ok.
for this, you are going to set unit to your global variable for your zergling, the player set to the local variable of the function you created 'Player Number". and the value of point to the point i had you create at the beginning of the tutorial.
now create another action under "then" (it must come after the create) to set variable. and we are going to set our global "Player Hero" once you have set that you should see your blue 0 in the brackets[ ] click on it and set it to the local variable "Player number". then set the == to unit - Last created unit.
now click on your map initialization trigger. add new action to run trigger "Math":
now add new action under - general select your custom function. set the parameter to the local variable you first made 'Player numbers"
And that's all. Fire that baby up and see if it creates a unit for you!
That was beautifully structured, thank you very much. We -noobs- need more explanatory tutorials. Like you said we need to understand why we do it and not only the way it's done. It helps especially those people who's mother language is not English. Thanks again.
Yea arrays can be really hard to wrap your head around but once you get them they are really useful. Thanks for the tutorial and advice. "if, then, else" actions I have been trying to learn but I feel I have a better understanding of what I can do with them now.
hey, nice tutorial, explained a whole lot, but it seems I need to experiment a lot before I can get used to all these "things".
Anyways, I'm stuck at the end of the tutorial
The function "player gets unit" won't show up in the -general tab when im trying to make an action. I tried restarting the editor with no luck... any ideas?
I've also tried to search for the function, but it seems to be non existent. Please help!
Thank you for such a easy going/easy to understand tutorial! My problem is, I had not used this type of math sequences in like... 11 years lol. So when it came down to Integers reals, and all them goodies, I had been lost in other tutorials from the many years of not having to use that type of stuff.
Back in high school honors math. The teachers said you would be using this stuff out in the real world... and i blew that off like yea if you were an physicist with mind boggling calculations. or a rocket scientist. Turns our I got into a passion for meteorology as I took my passion for surfing much more serious and Well the teacher came back to bite my arse on a few things in the past 11 years LOL. So I needed that refresher for my mind to remember some intermediate math basics, since I do not deal with that on an day to day basis, working two jobs home remodeling/Design/contractor and part time custom computer and network design. There is only a couple of things still left for me to understand how it works, but a quick scan over them ill figure that out no problem. Thanks again!
EDIT: DOH DOH DOH! I got home today took a look for 2seconds, I feel dumb as hell lol, basic math true, I just couldnt see how it came through the variables.
@Nebula99 the first trigger sets the playersnumber to = 5 in the math variable it sets the global to 2 - 7 which = -5 the function then takes the player number local variable which is 0 and adds the global and then + 1, the function also ask if the player number is equal to 1 to give that player the unit, back at the map init it says player gets unit, which is the function you made, and then you place the local variable which is set to 5 so essentially your just doing -5 + 5 = 0 + 1 = 1.. player 1 :) I am not sharp on explaining these kind of things as posted though the function can call information from triggers
So this artical is exactly what i was looking for, although I must be stupid or something. Unlike everyone else I still just don't get it. This is like the only thing in editor i don't understand. Not insulting the arthur he did a great job, but i just can't wrap my mind around it. Does ANYONE know anywhere else that might help me understand this better?
I was wondering if there is way to use triggers without creating a map just a extension mod for some reason sc2 editor doesn't allow me to create one unless i have a map. I've seen lots of mods on battle.net that gives huge changes which probably couldn't be done without using triggers.