1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Basic Trigger Editor Tutorial

Discussion in 'StarCraft II Tutorials' started by Wizardum, May 2, 2010.

  1. Wizardum

    Wizardum

    Joined:
    Sep 5, 2007
    Messages:
    360
    Resources:
    5
    Maps:
    2
    Spells:
    1
    Tutorials:
    2
    Resources:
    5
    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.

    [​IMG]

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

    [​IMG]

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

    [​IMG]

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

    [​IMG]

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

    [​IMG]

    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.

    [​IMG]

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

    [​IMG]

    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.

    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.

    [​IMG]

    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.

    [​IMG]

    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.

    [​IMG]

    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.

    [​IMG]

    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
     

    Attached Files:

    • Z_A.jpg
      Z_A.jpg
      File size:
      38 KB
      Views:
      3,049
    • Z_B.png
      Z_B.png
      File size:
      48.6 KB
      Views:
      3,108
    • Z_C.jpg
      Z_C.jpg
      File size:
      67.5 KB
      Views:
      3,362
    • Z_D.png
      Z_D.png
      File size:
      48.2 KB
      Views:
      2,996
    • Z_E.jpg
      Z_E.jpg
      File size:
      48 KB
      Views:
      2,991
    • Z_F.jpg
      Z_F.jpg
      File size:
      54 KB
      Views:
      3,006
    • Z_G.jpg
      Z_G.jpg
      File size:
      87.3 KB
      Views:
      2,958
    • Z_H.jpg
      Z_H.jpg
      File size:
      71.6 KB
      Views:
      2,960
    • Z_I.jpg
      Z_I.jpg
      File size:
      22.9 KB
      Views:
      2,961
    • Z_J.png
      Z_J.png
      File size:
      5.5 KB
      Views:
      3,016
    • Z_K.png
      Z_K.png
      File size:
      13.1 KB
      Views:
      2,977
    Last edited by a moderator: May 8, 2010
  2. killer1390

    killer1390

    Joined:
    Mar 19, 2008
    Messages:
    90
    Resources:
    0
    Resources:
    0
    Very nice tutorial. Wonderful way to start anyone with triggers.
     
  3. Pyritie

    Pyritie

    Joined:
    Nov 26, 2006
    Messages:
    11,357
    Resources:
    60
    Models:
    30
    Icons:
    9
    Packs:
    3
    Skins:
    12
    Tools:
    1
    Maps:
    1
    Tutorials:
    4
    Resources:
    60
    Could you attach your images to your post instead of hotlinking them?
     
  4. Avator

    Avator

    Joined:
    Aug 23, 2008
    Messages:
    2,309
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    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:
     
  5. Wizardum

    Wizardum

    Joined:
    Sep 5, 2007
    Messages:
    360
    Resources:
    5
    Maps:
    2
    Spells:
    1
    Tutorials:
    2
    Resources:
    5
    If I knew how they work, I'd add those features, but still I think this serves the purpose of a basic trigger editor tutorial, people can start good from this.
     
  6. ShadowFlare

    ShadowFlare

    Joined:
    Jun 30, 2008
    Messages:
    552
    Resources:
    0
    Resources:
    0
  7. mrzwach

    mrzwach

    Joined:
    Aug 1, 2009
    Messages:
    929
    Resources:
    3
    Tutorials:
    3
    Resources:
    3
    No, it isn't the same.

    You can't use them as parameters for functions, which kinda ruins the point.
     
  8. Wizardum

    Wizardum

    Joined:
    Sep 5, 2007
    Messages:
    360
    Resources:
    5
    Maps:
    2
    Spells:
    1
    Tutorials:
    2
    Resources:
    5
    oh didn't know about that, but it was just an anology to better understand what was a record. It doesn't support methods either, but well, that's something we have to live with
     
  9. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Records are Sc2 structs.
    Code (vJASS):
    struct gs_RECORD_NAME {
        type lv_member;
        type lv_member2;
    };


    Anyway, this tutorial looks very nice. And factual too. I'll check it more thoroughly, and if I don't find any problems, I'll approve it.

    EDIT: Attached the images, fixed the index, now I'll approve. =) Nice job.
     
    Last edited: May 8, 2010
  10. Zypher

    Zypher

    Joined:
    May 21, 2008
    Messages:
    215
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    Great tutorial, especially liked the part about records.
     
  11. Troynl

    Troynl

    Joined:
    Sep 27, 2008
    Messages:
    141
    Resources:
    0
    Resources:
    0
  12. Avator

    Avator

    Joined:
    Aug 23, 2008
    Messages:
    2,309
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    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.
     
  13. Troynl

    Troynl

    Joined:
    Sep 27, 2008
    Messages:
    141
    Resources:
    0
    Resources:
    0
    i have to retail version any1 know where i can find the veriable button?

    Edit: A Found it: Data-->New-->New Variable
     
    Last edited: Aug 21, 2010
  14. Avator

    Avator

    Joined:
    Aug 23, 2008
    Messages:
    2,309
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Hotkey is probably faster and probably the same as in beta: Ctrl+B
     
  15. kellym0

    kellym0

    Joined:
    Nov 28, 2009
    Messages:
    845
    Resources:
    51
    Models:
    49
    Skins:
    1
    Tutorials:
    1
    Resources:
    51
    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.
     
  16. Twisting

    Twisting

    Joined:
    Feb 17, 2008
    Messages:
    13
    Resources:
    0
    Resources:
    0
    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.