Outpost Universe Forums

Projects & Development => Outpost 2 Programming & Development => Topic started by: Sirbomber on October 26, 2009, 08:11:41 PM

Title: Distinguishing Triggers With Identical Callbacks
Post by: Sirbomber 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()]++;

}
Title: Distinguishing Triggers With Identical Callbacks
Post by: Hooman 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)
{
...
}
Title: Distinguishing Triggers With Identical Callbacks
Post by: Sirbomber on October 27, 2009, 08:13:13 AM
Hmmm, that will work.  Thanks.