Jump to content
Sign in to follow this  
Guest n707jt

[FS2004] Expressions in value tag not being computed

Recommended Posts

Guest n707jt

Hey guys,I am trying to design an XML fuel gauge for the C172 aircraft, which has a status bitmap at the bottom of the fuel gauge which will either display Fuel Insufficient if the time to fuel exhaustion is less than the time to the next GPS waypoint, or Fuel Ok if there is sufficient fuel onboard. I have used a Select tag at the bottom which toggles the corresponding bitmap to display depending on the value computed like such -

<Element>	<Position X="72" Y="305"/>	<Visible>(A:GPS IS ACTIVE FLIGHT PLAN, bool)</Visible>	<Select>	<Value>((A:fuel total quantity, gallons) (A:eng1 fuel flow GPH, gallons per hour) /) ((A:GPS WP DISTANCE, kilometer) (A:GPS GROUND SPEED, kilometer per hour) /) > if{ 1 } els{ 0 }</Value>	<Case Value="0">		<Image Name="FuelInsufficient.bmp" Luminous="Yes"/>	</Case>	<Case Value="1">		<Image Name="FuelOk.bmp" Luminous="Yes"/>	</Case>	</Select></Element>

However, I realised that the two expressions in the Value tag in the middle are not evaluating (they evaluate to 0), and hence, the entire expression always evaluates to the else clause.The expressions should be correctly defined as they are used further up in the XML file where they are evaluated within a String tag.Would very much appreciate any help that anyone could provide on this issue. Thanks to all in advance!

Share this post


Link to post
Share on other sites

Syntax for <Value> is different than the syntax used in <String> expressions. Try this instead:

<Value>  (A:fuel total quantity, gallons)  (A:eng1 fuel flow GPH, gallons per hour) /  (A:GPS WP DISTANCE, kilometer)  (A:GPS GROUND SPEED, kilometer per hour) /  >  if{ 1 } els{ 0 }</Value>

Of course, the real question is why you are calculating this twice (or more?). Why not encapsulate the calculation in a <Macro>, place it in an <Update> section and then use the @Macro to get the returned value for both the <String> and this <Element> section?


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

I tested your expression in isolation and it evaluated to 1 when the conditions agreed.However I did remove the parentheses and used > instead of >Something to try anyway...Danny

<Value>(A:fuel total quantity, gallons) (A:eng1 fuel flow GPH, gallons per hour) / (A:GPS WP DISTANCE, kilometer) (A:GPS GROUND SPEED, kilometer per hour) / >if{ 1 }els{ 0 }</Value>

Edit

Share this post


Link to post
Share on other sites
Guest n707jt
...Of course, the real question is why you are calculating this twice (or more?). Why not encapsulate the calculation in a <Macro>, place it in an <Update> section and then use the @Macro to get the returned value for both the <String> and this <Element> section?
Hi Bill,You're absolutely spot on... we should calculate this once and reuse it and that's what I've tried to do.In the element which displays this as a string I have done something similar to -
   <Element>    <Position X="72" Y="308"/>    <Value>((A:fuel total quantity, gallons)  (A:eng1 fuel flow GPH, gallons per hour) /) (>L:myTTE,hour)</Value>    <Text ...>        <String>%(L:myTTE,hour)%!2.2f!</String>    </Text></Element>

However, the string bit always evaluates to 0 (i.e. my local variable). Do I need to encapsulate it in an Update tag in order for it to periodically refresh?

Share this post


Link to post
Share on other sites
However, the string bit always evaluates to 0 (i.e. my local variable). Do I need to encapsulate it in an Update tag in order for it to periodically refresh?
Get rid of the parenthesis. Those are only allowed in <String> expressions. Also the unit "hour" is not valid, use "number" instead:
<Value>(A:fuel total quantity, gallons) (A:eng1 fuel flow GPH, gallons per hour) / (>L:myTTE,number)</Value>


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
Get rid of the parenthesis. Those are only allowed in <String> expressions. Also the unit "hour" is not valid, use "number" instead:
<String>%[b]([/b](L:myTTE,hour)[b])[/b]%!2.2f!</String>

<Value>(A:fuel total quantity, gallons) (A:eng1 fuel flow GPH, gallons per hour) / (A:GPS WP DISTANCE, kilometer) (A:GPS GROUND SPEED, kilometer per hour) / >if{ 1 }els{ 0 }</Value>if{ 1 } els{ 0 } is redundant. It'll work, but it's completely unnecessary as the stack in your expression will evaluate to either 0 or 1 anyway. There is no need to ever use if{ 1 } els{ 0 } together in any XML code for any reason. It just adds extra overhead.If you were to put that expression in a string directly:

<String>%((A:fuel total quantity, gallons) (A:eng1 fuel flow GPH, gallons per hour) / (A:GPS WP DISTANCE, kilometer) (A:GPS GROUND SPEED, kilometer per hour) / >)%!5.2f!</String>

It would print as 0 or 1 without any additional code.

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