Jump to content
Sign in to follow this  
rcbarend

Storing a variable

Recommended Posts

Guest depot_haldol

Gurus, Bill and all, you guys are an invaluable resource. My next question: I used the construct: (L:First, enum) (L:Second, enum) 2 * + ...etc... And it's working just fine. But as my gauge gets bigger, I'm realizing that I need to re-use that first RPN evaluation statement again and again. It makes sense to me to store it in an L:Var, for repeated use and to simplify later calculations, but I'm getting stuck. This doesn't work: (L:First, enum) (L:Second, enum) 2 * + (>L:Result)Basically, L:Result stays zero. What's the best way to go about it? Thanks.---Will

Share this post


Link to post
Share on other sites
Guest Vorlin

I can try this one but you want to let Tom, Jan, Bill, Jon (or someone else who knows for sure!) double check this:I'd try:<Macro Name="TheMacro"> @1 @2 2 * + </Macro>The @1 and @2 are place holders for arguments to be passed in, just like a function.Then call it with:<Value> @TheMacro((L:First, enum),(L:Second, enum)) </Value>To set the result into an L:Var, simply use:@TheMacro((L:First, enum),(L:Second, enum)) (>L:Result,enum)A nice thing about macros is that they don't have to be inside of elements or value tags in order to do the behind the scenes manipulations.I am a macro newbie myself... get a second opinion on this and I'm sure that there are many points I'm missing too. But, as far as I know, that example should meet your needs.Scott / Vorlin

Share this post


Link to post
Share on other sites
Guest depot_haldol

Errff, macros are scary, but that's how we learn, right? Thanks Scott. Any other takers?---Will

Share this post


Link to post
Share on other sites
Guest depot_haldol

Well, I have the macro up and running. Works great. Thanks again, Scott.---Will

Share this post


Link to post
Share on other sites

Maybe for your understanding.The reason why your original assignment didn't work is that you omitted the unit in (>L:Result). Probably the most common mistake in XML coding (at least for me :-) )About macros vs. "saved" calculations:Both methods are valid and have their pro's and con's, and it's not always that trivial which one to choose.But realise that there IS a big difference.In your first line, (L:Result,enum) gets a value assigned ONCE, which is fixed through the subsequent code. Even if L:First and L:Second are changed later on in the code.If you use the macro form: the value of L:Result is caculated EACH time at the moment you call the macro in the code, and uses the values of L:First and L:Second at the moment of calling.So realise this difference.Also, you may pay a performance penalty in the gauge, because the macro calculation is done at each time you call it in the code (which could cause a fps hit for very complex macros). Not really an issue, it's just so you know :-)Cheers, Rob Barendregt

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...