Author Topic: Distinguishing Triggers With Identical Callbacks  (Read 1527 times)

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Distinguishing Triggers With Identical Callbacks
« on: October 26, 2009, 08:11:41 PM »
I think I've asked this before...

Anyways, I have a bunch of SpecialTarget triggers that all have the same callback function.  In the callback function, I want to use GetSpecialTargetData to figure out which unit triggered it (so I can then figure out which player triggered it).  Problem is I also need to know which trigger is calling the callback function.  Any ideas?

Code: [Select]
SCRIPT_API void AddOneSomething()
{
    Unit Unit1;     // Triggering unit

    // Figure out who just triggered this trigger
    //GetSpecialTargetData( [trigger variable name], Unit1);

    // Give the player his/her/its something
    playerResource[Unit1.OwnerID()]++;

}
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Distinguishing Triggers With Identical Callbacks
« Reply #1 on: October 26, 2009, 11:38:14 PM »
Simply put, have separate callback functions for each trigger. It's kind of a crappy solution, but the only one that's really possible. It would have been nice if the trigger was passed to the callback function, but it isn't.

What you can do, if there is a significant amount of code in the callback, is just have small dummy callback functions that call the real code, and pass a parameter to distinguish where it's calling from.

Code: [Select]
export void Callback1()
{
DoWork(1);
}

export void Callback2()
{
DoWork(2);
}

...

void DoWork(int i)
{
...
}

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Distinguishing Triggers With Identical Callbacks
« Reply #2 on: October 27, 2009, 08:13:13 AM »
Hmmm, that will work.  Thanks.
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials