October 17, 200916 yr 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!
October 17, 200916 yr Moderator 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
October 17, 200916 yr Commercial Member 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
October 18, 200916 yr ...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?
October 18, 200916 yr Moderator 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
October 24, 200916 yr Commercial Member 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. Jon Blum Vertical Reality Simulations
Create an account or sign in to comment