Jump to content
Sign in to follow this  
Odaat

Do Arithmatic in <string> {case} Evaluations?

Recommended Posts

I've gotten a simple string case evaluation to work, but when I try any kind of arithmatic it just evaluates to 0:

This works:<String>Fuel Burn: %((A:NUMBER OF ENGINES, NUMBER))%{case}%{:4}%((A:Eng4 fuel flow GPH,gallons per hour))%{:1}%((A:Eng1 fuel flow GPH,gallons per hour))%{end}%!4.0d</String>This Doesn't:<String>Fuel Burn: %((A:NUMBER OF ENGINES, NUMBER))%{case}%{:4}%((A:Eng4 fuel flow GPH,gallons per hour)4*)%{:1}%((A:Eng1 fuel flow GPH,gallons per hour))%{end}%!4.0d</String>

Note the only difference is that I've tried to multiply Eng4 fuel flow by 4Any suggestions?Thank youPaul

Share this post


Link to post
Share on other sites

Hi,Try:%((A:Eng4 fuel flow GPH,gallons per hour) 4 *)% May be there were some spaces missing?Jan

Share this post


Link to post
Share on other sites

That did it; thanks! Are there some rules posted in the SDK or anywhere else as to where spaces are needed in an evaluation?

Share this post


Link to post
Share on other sites
That did it; thanks! Are there some rules posted in the SDK or anywhere else as to where spaces are needed in an evaluation?
None that I've ever found... However, if you think about it a bit, it's really common sense to use spaces to separate words, operators, and numbers in a sentence; which is all XML script is anyway! :( Imeanhowhardisittoreadthissentencewithoutspacestoseparatethewordsfromeachother? :(

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites
Guest ziporama
None that I've ever found... However, if you think about it a bit, it's really common sense to use spaces to separate words, operators, and numbers in a sentence; which is all XML script is anyway! :( Imeanhowhardisittoreadthissentencewithoutspacestoseparatethewordsfromeachother? :(
And they say reverse polish notation (postfix, or Yoda speak) was a good thing in XML... Not to use blatant sarcasm, I think it would have been so much better if it used octal to aid in the comprehension. This said, there is a tool to convert infix to postfix in the SDK - that seems to avoid this kind of outer space (or was that spaced out?) nonsense :->Etienne

Share this post


Link to post
Share on other sites

and I thought Fortran was unforgiving! Anyway here is the completed code. Thought I'd throw it in here in case anyone struggled with spaces as long as I did. Fuel Burn and Fuel Range in nm based on number of engines:

			<Element>				<Position X="180" Y="180"/>				<FormattedText X="150" Y="16" Bright="Yes" Length="150" Font="Arial" FontSize="14" LineSpacing="16" Color="#CD8DC5">				<String>Fuel Burn: %((A:NUMBER OF ENGINES, NUMBER))%{case}				%{:4}%((A:Eng1 fuel flow GPH,gallons per hour) (A:Eng2 fuel flow GPH,gallons per hour) (A:Eng3 fuel flow GPH,gallons per hour) (A:Eng4 fuel flow GPH,gallons per hour) + + +)				%{:3}%((A:Eng1 fuel flow GPH,gallons per hour) (A:Eng2 fuel flow GPH,gallons per hour) (A:Eng3 fuel flow GPH,gallons per hour) + +)				%{:2}%((A:Eng1 fuel flow GPH,gallons per hour) (A:Eng2 fuel flow GPH,gallons per hour) +)				%{:1}%((A:Eng1 fuel flow GPH,gallons per hour))%{end}%!4.0d gph</String>				</FormattedText>			</Element>			<Element>				<Position X="180" Y="195"/>				<FormattedText X="150" Y="16" Bright="Yes" Length="150" Font="Arial" FontSize="14" LineSpacing="16" Color="#CD8DC5">				<String>Fuel Range: %((A:NUMBER OF ENGINES, NUMBER))%{case}				%{:4}%((A:Eng1 fuel flow GPH,gallons per hour) (A:Eng2 fuel flow GPH,gallons per hour) (A:Eng3 fuel flow GPH,gallons per hour) (A:Eng4 fuel flow GPH,gallons per hour) + + + 60 / (A:FUEL TOTAL QUANTITY, gallon) r / 60 / (A:GPS Ground Speed, knot) *)				%{:3}%((A:Eng1 fuel flow GPH,gallons per hour) (A:Eng2 fuel flow GPH,gallons per hour) (A:Eng3 fuel flow GPH,gallons per hour) + + 60 / (A:FUEL TOTAL QUANTITY, gallon) r / 60 / (A:GPS Ground Speed, knot) *)				%{:2}%((A:Eng1 fuel flow GPH,gallons per hour) (A:Eng2 fuel flow GPH,gallons per hour) + 60 / (A:FUEL TOTAL QUANTITY, gallon) r / 60 / (A:GPS Ground Speed, knot) *)					%{:1}%((A:Eng1 fuel flow GPH,gallons per hour) 60 / (A:FUEL TOTAL QUANTITY, gallon) r / 60 / (A:GPS Ground Speed, knot) *)%{end}%!03d! nm</String>				</FormattedText>			</Element>

No doubt there is a more elegant way to do this, nevertheless, it works. Thanks for the help, guys.

Share this post


Link to post
Share on other sites
And they say reverse polish notation (postfix, or Yoda speak) was a good thing in XML... Not to use blatant sarcasm, I think it would have been so much better if it used octal to aid in the comprehension. This said, there is a tool to convert infix to postfix in the SDK - that seems to avoid this kind of outer space (or was that spaced out?) nonsense :->Etienne
Actually FS XML team didn't make the choice for rpn just to complicate gauge programmers, but because it's a very efficient way to handle a scriptying system like the one used in XML code. Most of complex arithmetic and logical operations can be managed with a bunch of very simple low level functions that use rpn method, something that wouldn't be possible with the standard infix notation.Tom

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...