• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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,201
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