• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Triggers] Using a variable as a trigger

Status
Not open for further replies.
Level 2
Joined
Apr 23, 2011
Messages
16
Hey guys, I'm trying to use a trigger variable and running into some problems.
The script goes something like this:
Code:
//globals
Trigger[999] test;
//end globals
void killUnits(unit u, unit u2)
{
    UnitKill(u);
}
void Test(unit u, unit u2)
{
   TriggerExecute(test[1],false,false);
}
void Init()
{
   unit u = CreateUnit();
   unit u2 = CreateUnit();
   test[1] = CreateTrigger("killUnits");
}

It errors when TriggerExecute() attempts to run. It gives the error that "killUnits" does not exist. Any help on how to call functions like this and have the correct variables?
All help appreciated!
 
Last edited by a moderator:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
killUnits is not a valid trigger function.

A valid trigger function looks like this
Code:
//  bool TriggerFunc (bool testConditions, bool runActions) {
//      if (testConditions) {
//          if (<conditions fail>) {
//              return false;
//          }
//      }
//
//      if (!runActions) {
//          return true;
//      }
//   
//      <do actions>
//      return true;
//  }

It must take 2 booleans and return a boolean.
It cannot take 2 units and return a void.

If you want to use a trigger function as a means of dynamic code or to create new threads, you will need to pass the arguments to it via global variables. This is how the GUI Action Defination set to start a new thread works.
 
Status
Not open for further replies.
Top