Triggers - Introduction To Triggers

Discussion in 'Tutorial Repository' started by WolfieeifloW, Feb 1, 2009.

  1. WolfieeifloW

    WolfieeifloW WEHZ Helper

    +372 / 0 / -0
    Introduction To Triggers
    Written By: Wolfie[NoCT]

    I know TriggerHappy187 has written one of these (over at Clan Mapz).
    I read through it and felt that it didn't give a whole explanation of how/what was in the Trigger Editor.
    Don't get me wrong, I think it's a good tutorial, but I wanted to further explain how the Trigger Editor works / the functions.
    I also believe that my tutorial is also more newb friendly.
    With that said, enjoy the tutorial!

    So, you've wandered on into the wonderful world of Warcraft III map editing?
    You're an amazing terrainer, but don't know anything about triggers?
    You've looked around in that scary Trigger Editor, and just sat there staring at a blank screen?
    Well then, you've come to the right tutorial.
    By the end of this, you'll (hopefully) fully understand how to create and edit triggers.

    Here's a quick rundown of what you'll see in this tutorial.

    1. Opening The Trigger Editor
    2. Parts Of The Trigger Editor
    3. Creating A Trigger
    4. Ending Words

    1. Opening The Trigger Editor
    To open the Trigger Editor, you can do one of two things:

    1. Press F4.
    2. Click on the 'a', [​IMG]
    You're now in the Trigger Editor, easy right? Right.

    2. Parts Of The Trigger Editor
    So, you've opened your Trigger Editor, and you're staring at this:
    Now, you're at a loss.
    This is the part you fear.
    You don't know what to do from here.
    Well, that's why you're reading this ;) !

    What you're looking at is called a "Trigger".
    If you look on the left hand side, you'll see what's called a "Treeview".
    It lists the names of the triggers you create.

    Before we get more into that, you'll notice a folder named "Initialization".
    These folders are called "Categories".
    As the name implies, they'll help you categorize all your triggers.
    This will make it easier to find each trigger you need later on when you have loads of triggers.
    For example, you can create a category for "spawning triggers", another category for "spell triggers", and another for "reviving triggers", etc.

    Notice how the toolbar you clicked on to enter the Trigger Editor has changed a bit.
    There's now a few more buttons then there was before:
    In order from left to right, these buttons are:

    • Variable Editor
    • Create New Category
    • Create New Trigger
    • Create New Comment Trigger
    • Create New Event
    • Create New Condition
    • Create New Action
    I'll explain each of these later.

    You'll notice right below the toolbar, there's two check boxes.
    One saying "Enabled" and one saying "Initially On".
    Don't worry about these two things for now, just leave them checked.

    Underneath this, there's a spot for "Trigger Comments".
    You can write comments in here that will help you remember what the proceeding trigger is doing/going to do.
    I recommend that you comment your triggers, regardless of your skill level.
    It'll make things a lot easier for you when you start having more and more triggers.

    Fairly basic so far, easy to understand? Good.

    Now, remember that cool new toolbar that I said I'd explain later?
    Well here we go!

    • Variable Editor
    In simple terms, variables are used to store information.
    This stored information can be used to carry information from one trigger to another.
    Variables are also used to fix memory leaks, which I won't go into detail about (if you want more info, look here or here) .
    For more in-depth looks at variables, there's multiple tutorials:

    The keyboard shortcut for the Variable Editor is "CTRL + B".

    • Create New Category
    Remember those "folders" in the Treeview?
    They were called categories.
    This button will create a new category:
    After pressing the button, the new category will come up.
    You can now name this category.
    Name it something meaningful so that you know what triggers this category contains.
    So for example, if this category is going to contain triggers related to spells;
    A suitable name for the category would be "Hero Spells" or something of the like.
    This way you know what kind of triggers are inside of the category at a quick glance.
    To create a category, the keyboard shortcut is "CTRL + G".

    • Create New Trigger
    The mother load of your map.
    These are what make your map function.
    When you press the Create New Trigger button, this is what you'll see:
    Triggers are what will make your map function.
    Without them, your map would just sit there.

    Notice how I renamed my Category to "Trigger Editor Intro".
    You'll also see that "Untitled Trigger 001" is highlighted right after making the trigger.
    Rename the trigger according to what it will do.

    For example, if the trigger is going to spawn units every couple seconds;
    Name the trigger something like "Periodic Spawn".

    You can also insert a Trigger Comment now, or you can do it later.

    The keyboard shortcut to make a new trigger is "CTRL + T".

    • Create New Trigger Comment
    Trigger Comments can be used to store notes, info, etc.
    Upon clicking the New Trigger Comment button, you'll be greeted with this:
    You can rename the comment to whatever name is desired, if you want.
    These can be useful for certain things, but most of the time the Trigger Comments on the triggers themselves are enough.
    Shortcut: "CTRL + M"

    • Create New Event
    Events are what cause the trigger to be fired.
    Say for instance, you want the trigger to run through when a unit dies.
    You'd use the event "Unit - A unit Dies".
    This is what it looks like when you create a new Event:
    Notice how I added in a Trigger Comment.
    This will help me remember what this trigger does without even having to read the code that I'll be putting in.

    Without an event, your trigger will not run.
    An event is what makes the trigger fire off.
    It's like if you're trying to get a bottle of pop to explode when you open it.
    Without shaking it first (which would be our "Event") it would never explode.
    As you can see, an event is needed to make the rest of the trigger work.

    I'll be explaining how to configure an event and use them in Part 3.
    The shortcut for creating a new event is "CTRL + E".

    • Create New Condition
    Conditions are what allow or deny the trigger to run.
    If the condition passes (is True), the triggers Actions will run.
    If the condition fails (is False), the triggers Actions will NOT run.
    This is what it will look like when you create a new condition:
    I'll explain conditions in more detail in Part 3.
    Shortcut is "CTRL + D".

    • Create New Action
    Actions are all the things that occur when the trigger runs.
    They can do almost anything.
    Actions are what make your map run;
    Without them, your map would just sit there.
    Here's what it looks like when you go to create a new action:
    Back to the bottle of pop.
    Remember how we wanted it to explode?
    The action of the pop exploding would be the explosion itself.

    Again, look at Part 3 for more of an explanation on Actions.
    Oh, and the shortcut for creating a new action is "CTRL + R".

    Well now look, you got scared for nothing.
    Pretty simple stuff so far? Yes, of course it is.

    3. Creating A Trigger
    So, you know all the aspects of the Trigger Editor, but now you have to put that knowledge to use.

    A couple things you'll need to know before we continue:

    1. Triggers can have multiple Events, Conditions, and, will most likely, have more then one Action.
    2. Triggers run instantly* (unless you have waits) .
    * - Instantly is actually something like 0.20 seconds.
    Even though there's this delay, there's something called "Trigger Queue";
    This means when the event occurs again and the trigger fires, if the trigger is already running from a previous fire-up, the first firing of the trigger will be queued and wait to be finished until after the second run-through is done.

    When you are configuring your trigger, you'll notice that there's Red and Blue values:
    These Red values are "required" values.
    They're values that need to be input before you can complete configuring the Event/Condition/Action.
    The Blue text is just changeable values.

    Reading is never as good as seeing, so let's get right to doing an example.

    First off, go to the Melee Initialization trigger and delete this action:
    Melee Game - Enforce victory/defeat conditions (for all players)
    Which will make your Melee Initialization trigger look like this:
    • Melee Initialization
      • Events
        • Map initialization
      • Conditions
      • Actions
        • Melee Game - Use melee time of day (for all players)
        • Melee Game - Limit Heroes to 1 per Hero-type (for all players)
        • Melee Game - Give trained Heroes a Scroll of Town Portal (for all players)
        • Melee Game - Set starting resources (for all players)
        • Melee Game - Remove creeps and critters from used start locations (for all players)
        • Melee Game - Create starting units (for all players)
        • Melee Game - Run melee AI scripts (for computer players)

    We delete this action so that we will not get victoried right away as we have no opponents.
    Anyways, onto our example.

    For our example, we will be making a footman spawn every 1.50 seconds at Player 1's starting location as long as Player 1 is still in the game.

    First off, we need to make an event.
    What do we use for our event you ask?
    Well, since we are spawning a footman every 1.50 seconds, we'll use the event "Time - Periodic Event":

    At default, as you can see, the trigger will be set to 2.00.
    We want a spawn every 1.50 seconds.
    So go ahead and change the 2.00 to 1.50 and then press OK.
    This is what your trigger should look like:
    • Periodic Spawn
      • Events
        • Time - Every 1.50 seconds of game time
      • Conditions
      • Actions
    That's it for the event!
    That was easy enough wasn't it? Of course it was.

    Now, for this trigger we also need a condition.
    The condition is "as long as Player 1 is still in the game." as said above.
    So, for this condition we'll use a "Player Slot Status Comparison":

    A "Slot Status" checks if a certain slot is being used, unused, or has left.
    Used would be if the user is playing and in the game.
    Unused is when the slot never had a player to begin with.
    Has left is when the player has left the game.

    Getting back to our condition;
    Luckily for us, the condition is already setup for us :) !
    This condition is basically saying "If Player 1 is playing".
    This is what your trigger should now look like:
    • Periodic Spawn
      • Events
        • Time - Every 1.50 seconds of game time
      • Conditions
        • (Player 1 (Red) slot status) Equal to Is playing
      • Actions

    So, if Player 1 is indeed playing, the Actions will get run.
    If Player 1 isn't playing, the rest of the trigger will not get run.
    Speaking of Actions, that's what we have to configure next.

    The finale!
    The big ol' scary actions :eek: !
    Well actually, they're not really scary at all.
    Let's dissect what we're trying to do here:

    1. We want to spawn a unit
    2. We want 1 unit to spawn
    3. We want that unit to be a Footman
    4. We want the Footman to be owned by Player 1
    5. We want the Footman to spawn at Player 1's starting location
    So, problem 1: Spawning a unit.
    For this, we use the action "Unit - Create Units Facing Angle":

    Again, luckily, most of the Action is already setup for us.
    You'll notice the action is already ready to create 1 Footman for Player 1 (Red).
    However, the action is going to spawn the unit at "(Center of (Playable map area))".
    We want the unit to spawn at "(Player 1 (Red) start location)".
    So, to change this, click on (Center of (Playable map area)).

    This is what will come up:

    We don't need the "Center Of Region", we need a "Player Start Location".

    So, click on the Function: box, and select Player Start Location:
    Again, Player 1 (Red) is already filled in for us, so just click OK.

    You'll come back to the menu that used to look like this:

    Except it will now look like this:

    Click OK on this box to return to the trigger editor window.
    You're trigger should now look like this:
    • Periodic Spawn
      • Events
        • Time - Every 1.50 seconds of game time
      • Conditions
        • (Player 1 (Red) slot status) Equal to Is playing
      • Actions
        • Unit - Create 1 Footman for Player 1 (Red) at (Player 1 (Red) start location) facing Default building facing degrees

    You can now test your map (CTRL + F9) .
    A Footman should spawn every 1.50 seconds at your starting location.

    You've just created your first trigger!

    4. Ending Words
    I hope this tutorial has helped you.
    Any comments/suggestions are welcome (as long as their constructive) .
    Constructive criticism is allowed, flaming is not.

    Here's a little challenge for the people who used this tutorial;
    A little note first though:
    Please don't post the answers/solutions here.
    Just try them yourself, them download the corresponding map.
    The maps attached are the answers.
    Anyways, here's the challenges:

    1. Make 2 Footman spawn at a time.
    2. Make a Footman spawn for Player 2 instead of Player 1 (still at Player 1's start location) .
    3. Make a Footman spawn for Player 2 at Player 2's starting location.
    Enjoy the challenges!

    Attached Files:

    • Like Like x 2
  2. Darthfett

    Darthfett Super Mod

    +614 / 0 / -0
    Didn't read through the whole thing (got to about section 3), but I wanted to give you a little bit of feedback.

    In my opinion, you should leave the hardest parts, such as the Variable editor for last. Instead, start with the very basics of what the Trigger Editor is: Triggers. They are made up of Events, Conditions, and Actions. I think by explaining those from the start, you'll be able to get the reader familiar with the parts they need to understand the most, right off the bat.

    Also, all people who come to custom map creation, are either going to ignore the trigger editor completely and make a melee map, or they are simply going to delete the Map Initialization trigger. Either way, that trigger does not really need explanation, especially if you're trying to keep it simple for the newbies.

    Another point: The trigger comments and folders/categories aren't really very complicated. They're comments and sorting helpers. You could probably put that as a side note.

    Lastly, if you're trying to teach this to the first-time mapper, do NOT go into custom scripts, leaks, JASS, any of that stuff. Not only will it make them extremely confused, but it will turn them away from mapping. Once they've made their own private maps, they will begin to ask questions about how to do more complicated stuff, like get rid of lag, as they will want to release a map that beats DotA. :rolleyes: This is when they need to be taught leaks, not when they're simply trying to learn how to create a unit.

    I think the tutorial is a good start, but needs a lot of work before it becomes really useful to the newbies. Also, the link to variables is good, since that is where they will be headed next, but putting it in the middle, and telling them they don't need to worry about it, isn't all that much help.
    • Like Like x 2
  3. WolfieeifloW

    WolfieeifloW WEHZ Helper

    +372 / 0 / -0
    That's why I didn't go into details about the Variable Editor.
    I'm just showing all the parts that are in the Trigger Editor.
    If I explain what every other button/place does except for the Variable Editor, that will leave them wondering what that X button does.
    It might even make them search the tutorial for it instead of reading through.

    Again, I just told them to get rid of the one action to prevent that silly Victory message coming up.
    There's even a WC3 code section to show them what it should look like.
    It's not really confusing or anything to them :p .

    I did explain that they're used for notes and that.

    I only talked about removing one of the leaks.
    And I explain/teach that after I teach them how to make the trigger without it.
    If they're confused, they can just stop since they already have achieved making a footman spawn.
    Also, they need this knowledge for one of my challenges ;) !
    If someone that actually needs/has used this tutorial says it's too confusing, I'll reconsider taking it out.

    Again, it's with the variable editor part.
    Wouldn't want to post a random link somewhere else in the tutorial.

    Thanks for all your feedback though.
  4. Darthfett

    Darthfett Super Mod

    +614 / 0 / -0
    What I meant was simply to move the Variable editor section to the end, as it is much more complicated than making a footman spawn. It does belong in the tutorial, just not in the very beginning where new people will begin reading. That way, they don't have to jump around in order to start learning harder things.
  5. WolfieeifloW

    WolfieeifloW WEHZ Helper

    +372 / 0 / -0
    You mean put it at the end right before step 3?
    Well, just remember I did it first because I explained the icons in order from left to right.
    Maybe I can explain them from right to left, so Variable Editor is last?
  6. marvey323

    marvey323 Member

    +1 / 0 / -0
    I'm new at map making and this was one of the first threads that came up when I went to do a general search. Quite informative for beginners!
  7. WolfieeifloW

    WolfieeifloW WEHZ Helper

    +372 / 0 / -0
    Thank you for the kind comment :) !

    Anymore comments/suggestions?
  8. vypur85

    vypur85 Hibernate

    +797 / 0 / -0
    I still have to agree with Darfett about the leaks. Ditch the leak section and use links instead. To use variable setting example, just simply use 'Unit variable' and show the example of how to use the variable. Giving out leak ideas to newbies will really confuse them.
  9. WolfieeifloW

    WolfieeifloW WEHZ Helper

    +372 / 0 / -0
    I might just take the whole variable part out about the custom scripts.
    I'll just say a quick little thing about memory leaks then links.

    Sound good?
  10. BlackRose

    BlackRose Forum User

    +239 / 0 / -0
    I never read any tutorials when I learnt how to do basic GUI, I just looked at Blizzard's

    But maybe you should add something like, this tutorial won't help you alone, you will need to play around with it before you understand.

    Looking through other maps (GUI coded) is also a good way to learn.

    Just my opinion, interesting tutorial, but I didn't read everything.

    - How long did it take to put all those icons T_T, I hate having to go on ImageShack and keep putting in images.
    - What windows theme is that? is it for Vista?

    EDIT: Cannot +REP, must spread.
    • Like Like x 1
  11. WolfieeifloW

    WolfieeifloW WEHZ Helper

    +372 / 0 / -0
    Well this is an "Introduction" to them.
    It's not supposed to fully teach you how to use triggers.

    The images, not long at all to upload.
    Longer to edit them (crop, etc.) .
    And yes, Vista (Home Basic) .

    EDIT: Thanks for the comment.
    • Like Like x 2
  12. wraithseeker

    wraithseeker Tired.

    +122 / 0 / -0
    This is good Wolfie.
  13. WolfieeifloW

    WolfieeifloW WEHZ Helper

    +372 / 0 / -0
    Thank you ;) !

    I'll be going over this guide tonight or tomorrow and fixing up anything I see wrong.
  14. Romek

    Romek Super Moderator Staff Member

    +961 / 0 / -0
    I don't think Events, Conditions and Actions are explained enough. Most people get the hand of this stuff the moment they even open the editor, and if they don't, seeing "These cause the trigger to run" will definitely not be enough.

    And the leaks bit will just confuse them; it's not even well explained.
  15. vypur85

    vypur85 Hibernate

    +797 / 0 / -0
    > Sound good?

    Good, I guess. But not too convinced before you really make the edit.

    And, I'd say that the tutorial seems to be just nice, except for the leak part. It's hard to really judge. Because I feel everything explained in there are very simple stuff (I'm already too familiar with basic GUI WE). So, I guess it's best to let the newbie to comment on how 'good' it is - if there's any, that is.
  16. Sooda

    Sooda Diversity enchants

    +318 / 0 / -0
    > * - Instantly is actually something like 0.20 seconds.
    Even though there's this delay, there's something called "Trigger Queue";
    This means when the event occurs again and the trigger fires, if the trigger is already running from a previous fire-up, the first firing of the trigger will be queued and wait to be finished until after the second run-through is done.

    Where comes that 0.2 second info? Trigger can not be interrupted until it starts to wait. While waiting other trigger may change paused trigger data if they share same variables. After wait trigger can not be interrupted again. Trigger becomes vulnerable while waiting and is solid as rock when continued.
    Only one trigger can be active at time, others are paused and wait in trigger queue meanwhile.

    I assume you are speaking about GUI trigger queue. It is trigger queue made for map makers. With that you have bit more control over triggers. In the end all those triggers find their way to games inner trigger queue. I was speaking how that inner trigger queue works -- everything ends up there.

    > [Tutorial] Introduction To Triggers: Further Explained

    Name points to comprehensive lesson while currently it whirls around tiny part of trigger editor. It goes specific soon and stays so until end.

    While trying to teach most in short time, memory leaks bring up more questions than giving clear picture of trigger. Units can be spawn without memory leak part just fine.
    To be picky and putting myself into shoes of first comer I would assume I need to use that custom script after every variable use. I would try to remove all short of things with your given script, soon I would get into trouble.
    I see this tutorial as step by step practical example how to create working trigger in game. Currently it lacks 'further explained' part. I have no solid opinion what is needed more. Daelin has best tutorial about triggered abilities, he explained trigger editor general idea, possibilities and limitations well.
    Pictures even help to familiarize editor easier though there is risk to add too much of them.
  17. WolfieeifloW

    WolfieeifloW WEHZ Helper

    +372 / 0 / -0
    I did a test for the 0.2 seconds.

    I removed the leak section.
    Added some more explanation to things.

    Comments are appreciated.

    EDIT: Can the title of this thread be changed to just "Introduction To Triggers".
  18. Romek

    Romek Super Moderator Staff Member

    +961 / 0 / -0
  19. WolfieeifloW

    WolfieeifloW WEHZ Helper

    +372 / 0 / -0
    Thank you very much Romek.

    For the people that read this, feel free to drop a comment.
    Or even suggestions/criticism.
  20. Romek

    Romek Super Moderator Staff Member

    +961 / 0 / -0
    You may want to fix up your BB code a little so it displays properly at the WET site.
    Stop nesting your colour tags. :D

    Edit: I believe when using default colours for the [COLOR] tags, the colour should be in quotation marks.
    [NOPARSE]So it's Text and not [/NOPARSE].

    Clearly, it works here, and not there.

Share This Page