• 🏆 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!

Trying a custom action for the first time

Status
Not open for further replies.
Level 14
Joined
Aug 30, 2004
Messages
909
I want a custom action to integrate two vectors. I came up with this:

  • Integrate
    • Options: Action, Create Thread
    • Return Type: Real
    • Parameters
      • VectorA Magnitude = 0.0 <Real>
      • VectorB Magnitude = 0.0 <Real>
      • VectorA Angle = 0.0 <Real>
      • VectorB Angle = 0.0 <Real>
    • Grammar Text: Integrate(VectorA Magnitude, VectorB Magnitude, VectorA Angle, VectorB Angle)
    • Hint Text: (None)
    • Custom Script Code
      • Ax = 0.0 <Real>
      • Ay = 0.0 <Real>
      • Bx = 0.0 <Real>
      • By = 0.0 <Real>
      • tempReal = 0.0 <Real>
    • Actions
      • Variable - Set Ax = (VectorA Magnitude * (Cos(VectorA Angle)))
      • Variable - Set Ay = (VectorA Magnitude * (Sin(VectorA Angle)))
      • Variable - Set Bx = (VectorB Magnitude * (Cos(VectorB Angle)))
      • Variable - Set By = (VectorB Magnitude * (Sin(VectorB Angle)))
      • Variable - Set Ax = (Ax + Bx)
      • Variable - Set Ay = (Ay + By)
      • Variable - Set tempReal = (Square root(((Ax * Ax) + (Ay * Ay))))
      • General - Return tempReal
This will not compile and I get an error saying: Script failed to compile: Implicit cast not allowed (See Trigger Editor for more details)


I looked it up and they say that this is the result of me trying to return a variable of the wrong type...but all my variables and parameters and return variables are real.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
I want a custom action to integrate two vectors. I came up with this:
Um what?! I do not think this is the right site to ask how you intigrate a vector with respects to another vector as not even second year university mathimatics covers vector intigration with respects to a constant let alone vector integration with respects to a vector.

What your function appears to be doing is returning the magnitude of a vector sum. I do not see how that has anything to do with integration.

Custom Script Code
Ax = 0.0 <Real>
Ay = 0.0 <Real>
Bx = 0.0 <Real>
By = 0.0 <Real>
tempReal = 0.0 <Real>
Is that really custom script? If so then you are missing any type identifiers on the variables.

Actually come to think of it, SC2 has no real type... they use fixed.
 
Level 14
Joined
Aug 30, 2004
Messages
909
What your function appears to be doing is returning the magnitude of a vector sum. I do not see how that has anything to do with integration.

Is that really custom script? If so then you are missing any type identifiers on the variables.

Actually come to think of it, SC2 has no real type... they use fixed.

Sorry, the *trigger* */trigger* feature doesn't appear to translate SC2 code very well. None of that that was custom script. The Custom Script Code is just an empty line. The variables underneath it are parameters.

I wanted to add the two vectors, not integrate them, you are correct. I used the wrong word. The math is right, I think, that's not what I need help with. I need help with the fact that the custom action won't compile at all.

I don't know what you mean when you say "SC2 has no real type". Almost all my variables are "real."
 
Level 14
Joined
Aug 30, 2004
Messages
909

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
Code:
bool auto_gf_Integrate_TriggerFunc (bool testConds, bool runActions) {
    fixed lp_vectorAMagnitude = auto_gf_Integrate_lp_vectorAMagnitude;
    fixed lp_vectorBMagnitude = auto_gf_Integrate_lp_vectorBMagnitude;
    fixed lp_vectorAAngle = auto_gf_Integrate_lp_vectorAAngle;
    fixed lp_vectorBAngle = auto_gf_Integrate_lp_vectorBAngle;

    // Variable Declarations
    fixed lv_ax;
    fixed lv_ay;
    fixed lv_bx;
    fixed lv_by;
    fixed lv_tempReal;

    // Variable Initialization
    lv_ax = 0.0;
    lv_ay = 0.0;
    lv_bx = 0.0;
    lv_by = 0.0;
    lv_tempReal = 0.0;

    // Implementation
    lv_ax = (lp_vectorAMagnitude * Cos(lp_vectorAAngle));
    lv_ay = (lp_vectorAMagnitude * Sin(lp_vectorAAngle));
    lv_bx = (lp_vectorBMagnitude * Cos(lp_vectorBAngle));
    lv_by = (lp_vectorBMagnitude * Sin(lp_vectorBAngle));
    lv_ax = (lv_ax + lv_bx);
    lv_ay = (lv_ay + lv_by);
    lv_tempReal = SquareRoot(((lv_ax * lv_ax) + (lv_ay * lv_ay)));
    return lv_tempReal; //This is what you return (correct).
    return true; //This is what GUI appends onto your return.
}

So why is GUI appending that extra true? Because you request it run in its own thread. Inorder for it to run in its own thread, the function must be attached to a trigger to run. Inorder for this attachment to be valid, it has to return a bool. This bool takes dominence over any return type you specify thus an error occurs when you do try and return a correct type. This is an extreemly logical fault but still a fault with the GUI of the editor (it should not allow you to cause such results).

The solution to this is fortunatly very easy. Just turn off the create thread flag. Something that is meant to return a value can not possibly be threaded in an efficient way.
 
Level 14
Joined
Aug 30, 2004
Messages
909
Code:
bool auto_gf_Integrate_TriggerFunc (bool testConds, bool runActions) {
    fixed lp_vectorAMagnitude = auto_gf_Integrate_lp_vectorAMagnitude;
    fixed lp_vectorBMagnitude = auto_gf_Integrate_lp_vectorBMagnitude;
    fixed lp_vectorAAngle = auto_gf_Integrate_lp_vectorAAngle;
    fixed lp_vectorBAngle = auto_gf_Integrate_lp_vectorBAngle;

    // Variable Declarations
    fixed lv_ax;
    fixed lv_ay;
    fixed lv_bx;
    fixed lv_by;
    fixed lv_tempReal;

    // Variable Initialization
    lv_ax = 0.0;
    lv_ay = 0.0;
    lv_bx = 0.0;
    lv_by = 0.0;
    lv_tempReal = 0.0;

    // Implementation
    lv_ax = (lp_vectorAMagnitude * Cos(lp_vectorAAngle));
    lv_ay = (lp_vectorAMagnitude * Sin(lp_vectorAAngle));
    lv_bx = (lp_vectorBMagnitude * Cos(lp_vectorBAngle));
    lv_by = (lp_vectorBMagnitude * Sin(lp_vectorBAngle));
    lv_ax = (lv_ax + lv_bx);
    lv_ay = (lv_ay + lv_by);
    lv_tempReal = SquareRoot(((lv_ax * lv_ax) + (lv_ay * lv_ay)));
    return lv_tempReal; //This is what you return (correct).
    return true; //This is what GUI appends onto your return.
}

So why is GUI appending that extra true? Because you request it run in its own thread. Inorder for it to run in its own thread, the function must be attached to a trigger to run. Inorder for this attachment to be valid, it has to return a bool. This bool takes dominence over any return type you specify thus an error occurs when you do try and return a correct type. This is an extreemly logical fault but still a fault with the GUI of the editor (it should not allow you to cause such results).

The solution to this is fortunatly very easy. Just turn off the create thread flag. Something that is meant to return a value can not possibly be threaded in an efficient way.

Excellent, thanks.
 
Status
Not open for further replies.
Top