GUI - Triggering for Dummies (custom actions and functions)

Tutorial by GFreak45


Triggering Basics

In this tutorial we will be going over 2 things, custom actions and functions. These are very usefull because you can make it much faster to do more routine actions or create functions that get complex values with mathematics or even run off variables.


We will begin with Custom Actions. When you first create one (via right clicking the left hand box for triggers, highlighting new, and selecting New Action Definition. You should get a picture that looks like this on the right:

*Traceline is only the name of the function being made, it has nothing to do with what is actually in the function.

Each of these does different things but i will explain the most important parts first.
Returns and parameters: In custom actions you will not use returns, they are only for functions, but parameters are important to make your custom actions as versatile and fluid as possible. A parameter is essentially one of the red or green options on actions and functions that you fill in. It is a field custom to that specific instance of this action. It is similar to a local variable because it is attached only to a specific action. There are many types ranging from variable data types to presets (operators like !=, <=, ==, or true/false).

the parameter field should look like the local variable field in a trigger after you define some locals, like this:
I = 0 <integer>
P = == <Any Option Parameter>

The next field we will look at is the Grammar Text. This is the field at the bottom of the trigger editor when you create a new action. As an example this should look like this:


where (All Players) and Debug are the default parameters, the green field is what they have already set, and any red paramaters are ones that must be set before the trigger containing the action can be activated, you can create these with paramaters that have the option no default value checked just above the default value when they are selected.
You set this by setting the Grammar Text field to whatever text you want without the parameters put in, include a space for each parameter, then go back and select it with the drop down menu on the bottom. This will input the parameter then walah, you action will look nice and pretty when you select it in the trigger editor.

The name of the Action is what will be displayed in the Editor when selecting an action, and if the function name is based off the action name, it will be the same as the name without any spaces. This is for use in custom text, you call that exact text to do this action.

Next is the Hint Text, that is simply the grayed out text along the bottom, telling what each action/function does.

Custom Text is a place where you can write out your actions rather than selecting them, but until the custom coding program for the galaxy editor is finished this wont be something to really get into.

Finally the local variables and custom actions. This part is essentially a trigger. The only difference is you can use the parameters as well, then when set by the user they will fill in the options set to those parameters.


In order for me to properly explain functions you must understand variables. Essentially a function is like a variable in that, they take something and return something. like this:

set variable X[index] = data type of the variable

function FunctionName takes Parameters returns data type of the return

so basically, a function with a return type of a unit, can replace a field in an action that requires a unit, like damage unit: the victim can be set to a custom function with a return type unit.

so now we will create an ability with a custom action and a custom function to fit our needs.
this ability will be based off the snipe ability (off the ghosts), the ability will do 2 things: Blink behind the target unit and then deal damage in an aoe. Think of how you could do that with 1 action and 1 function and try it out, then check this:


Blink Area Damage
Return Type: (None)
 Blinker = No Unit <Unit>
 Facing Point = No Location <Location>
 Blink Point= No Location <Location>
 Real = 50.0 <Real>
 Integer = 2 <Integer>
Grammar Text: Moves Blinker to Blink Point facing Facing Point and deals Real damage in a Integer Radius.
Hint: Moves a unit to a point and deals damage in a radius around that point.
Local Variables
 Unit - Move Blinker to Blink Point facing Facing Point
 Unit Group - Pick Every unit within Real(Integer) of Blink Point matching conditions (Owner of Matching unit (==) enemy of Owner of Triggering Unit) and do actions
  Loop Actions
   Unit - Cause Blinker to damage Picked Unit dealing Real damage with the effect Psionic Storm (Damage)


Point Behind Unit
Return: (Location)
 Unit = No Unit <Unit>
Grammar Text: Behind Unit
Hint: Gets the point behind the selected unit.
Local Variables
 General - Return (Position of Unit offset by 1.0 in the direction of ((Facing Angle of Unit) + 180))

and here we wrap it all up nicely in a 3 element trigger:

Full Trigger
 A unit finishes casting an ability targeting a unit
 Ability being cast = Snipe (i forget the real name)
 Unit - Move Triggering Unit to (Behind Target Unit of ability cast) facing (Position of Target unit of ability cast) and deal 50.0 damage in a 2 Radius

if you can get that without checking the spoilers first you are golden, now go out an use this to your advantage and create functions and actions that make your life easier :)

Here are some ideas you can try:

A Damage action that avoids loops in triggers fired by damage by turning off the trigger it is in, dealing the damage, then turning the trigger back on.
A Deal aoe damage action targeting a point a radius and a source as the parameters
A function returning a point in relation to a unit specific to what direction it is facing, example above

A dialog box with all labels/buttons included with spacing based on the ammount of dialog items
A chain lightning action dealing damage to a target then bouncing to a max number of additional targets 1 at a time but never hitting the same target twice.
A function returning the damage reduction factor of a unit by dealing 1 damage to it then checking how much was actually dealt due to reduction, then setting the units health back to what it was

This goes on to:

Click here to comment on this tutorial.
Tutorials submitted by users are copyright of the original author. All other content on this site is copyright
Copyright is secured automatically upon creation, and does not require registration