Author Topic: Getspecialtargetdata - Does It Work?  (Read 1634 times)

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Getspecialtargetdata - Does It Work?
« on: June 14, 2010, 01:21:12 PM »
I tryed to do some things with special targets. I wanted to do something like in e11, but if i use GetSpecialTargetData the game crashes. Does that work after all or is it my fault? And do you know how dynamix did that in e11?
Example:
Code: [Select]
GetSpecialTargetData(Trig, SpecialTriggerUnit);
SpecialTriggerUnit.SetCargo(mapInterColonyShuttle, mapNone);
Praise the mighty light towers!!!

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3237
Getspecialtargetdata - Does It Work?
« Reply #1 on: June 14, 2010, 03:31:33 PM »
Yes it works.  I use it all the time.

You are using it in a trigger callback function, yes?  And the trigger that calls that function is a Special Target Trigger?
"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 Flashy

  • Sr. Member
  • ****
  • Posts: 391
Getspecialtargetdata - Does It Work?
« Reply #2 on: June 14, 2010, 03:33:32 PM »
Yes. I'll look at my code again. Maybe I made a mistake somewhere
Praise the mighty light towers!!!

Offline Moley

  • Jr. Member
  • **
  • Posts: 95
Getspecialtargetdata - Does It Work?
« Reply #3 on: June 14, 2010, 08:41:32 PM »
that is not a lot of code... could post more?
I HATE SPELLING!!!!!!
if i spell something or screw up grammer,
ignore it or tell me if you dont understand what i typed.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Getspecialtargetdata - Does It Work?
« Reply #4 on: June 15, 2010, 02:08:39 AM »
You haven't posted the context of the code. It could still be in the wrong spot.


Try something like this:
Code: [Select]
struct ScriptGlobal
{
  Trigger specialTargetTrigger;
};
ScriptGlobal scriptGlobal;

Export void InitProc()
{
  scriptGlobal.specialTargetTrigger = CreateSpecialTargetTrigger // etc. ...
  // ...
}

Export void SpecialTargetCallback()
{
  Unit specialTargetUnit;

  GetSpecialTargetData(scriptGlobal.specialTargetTrigger, specialTriggerUnit);
  specialTriggerUnit.SetCargo(mapInterColonyShuttle, mapNone);
}

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Getspecialtargetdata - Does It Work?
« Reply #5 on: June 15, 2010, 07:36:23 AM »
So you have to put the trigger's name into getspecialtargetdata? I thought it returns the trigger that called that function. Anyway, it works now! Thank you Hooman.
Praise the mighty light towers!!!

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Getspecialtargetdata - Does It Work?
« Reply #6 on: June 15, 2010, 10:47:52 PM »
Lol, I just copied and pasted your code for that part really. I didn't even check if it was correct. :P

But then, I assumed a crashing error, meaning it at least compiled, so your datatypes were at least right. That and your variable names seemed to imply the data type.


At any rate, now that I'm checking, the SDK has this to say:
Code: [Select]
// Special Target Trigger/Data
OP2 Trigger __fastcall CreateSpecialTarget(int bEnabled, int bOneShot, Unit& targetUnit /* Lab */, map_id sourceUnitType /* mapScout */, const char* triggerFunction);
OP2 void __fastcall GetSpecialTargetData(Trigger& specialTargetTrigger, Unit& sourceUnit /* Scout */);


Btw, it makes no sense to assume the trigger callback knows what trigger caused it to fire, since there are no parameters (or "this" pointer) telling what trigger object caused the trigger callback to fire. In fact, you can have more than one trigger, possibly of completely different types, that all call the same trigger callback when they fire. There is no real way to distinguish what trigger caused it to fire in that case. The best you can do, is check each trigger to see if it fired, but that's still ambiguous if two of them fire at the same tick.

I've kind of found that to be an annoying limitation of the trigger system in Outpost 2. I think the trigger callbacks would have been better if they were defined along the lines of:
Code: [Select]
Export void TriggerCallbackFunction(Trigger& trigger) { /* ... */ }

Or perhaps passed some kind of generic context value, which might very well have been cast to a Trigger reference, or used to build one from an id/index value. Or perhaps just used raw as your own index of some sort. But then, you'd also have to modify each trigger creation function to add a context parameter or add a method to the trigger class to set the context value.
 
« Last Edit: June 15, 2010, 10:58:49 PM by Hooman »