Jump to content
Sign in to follow this  
Guest greenco

Need help with "IF/ELS" Syntax

Recommended Posts

Guest greenco

I am trying to get my head around how I should use the " if / els " statement to do a simple task!!!I have looked everywhere, I could think of, and I can' find any simple examples that help me. I thought I picked out a simple gauge, that would not pose too big of a challenge. WRONG!!!!I have been working on this for hours and I finally decided give up and ask the pros for help. I want to build a Fuel Flow gauge, that will be used on aircraft with either one or two engines. I tried to use the following piece of code to accomplish this. The "IF" portion does not work, but the code after the "ELS" portion does work. I wanted to find out how many engines the aircraft had. If it had two engines then I wanted to add the two fuel flow quantities together and display that value on the gauge. If it had one engine then I wanted to display that fuel flow value on the gauge. What is wrong with this code?if{ (A:NUMBER OF ENGINES, NUMBER)2 }%((A:Eng2 fuel flow GPH,gallons per hour)(A:Eng1 fuel flow GPH,gallons per hour)+)%!4.1f!els{ %((A:Eng1 fuel flow GPH,gallons per hour))%!4.1f! }I suspect that I have left out a parentheses or space somewhere. greenco

Share this post


Link to post
Share on other sites

Remember, you're writing RPN here:(A:NUMBER OF ENGINES, NUMBER) 2 == if{(A:Eng2 fuel flow GPH,gallons per hour) (A:Eng1 fuel flow GPH,gallons per hour) + (>G:Var1)}els{(A:Eng1 fuel flow GPH,gallons per hour) (>G:Var1)}%((G:Var1))%!4.1f!OK, so you don't really need to break the thing out by using a Value tag, but when you have as much trouble as I do with XML, it's a lot easier.Remember, the left hand "brace" must immediately follow the if and els statements (no spaces.)Also, if your aircraft has only one engine, the fuel flow for engine two will be zero, so this exercise is somewhat moot. You can just add the two fuel flow variables together for your string and be done with it.Doug

Share this post


Link to post
Share on other sites

the general sytax you will need is:%((condition))%{if}%((what to display if the condition meets))%{else}%((what to do if it meets not))If you use this "if - then" in a string, you need to use else instead of els.BTW, you can find dozens of examples for this in the default gauges - especially in the MDFs like the 747's primary flight display.So this should work:%((A:number of engines,number) 2 ==)%{if}%((A:Eng2 fuel flow GPH,gallons per hour) (A:Eng1 fuel flow GPH,gallons per hour)+)%!4.1f!%{else}%((A:Eng1 fuel flow GPH,gallons per hour))%!4.1f!%Hope this helps

Share this post


Link to post
Share on other sites
Guest greenco

Doug your code did not work. It gave me " 0.0 " and it would not change, when I increased the throttle. When I tried to add the two fuel flows together and use that in a statement, as you suggested, it would only display the fuel flow for one engine, but it would adjust.Herbie your code did not work either. When I used it it would display the fuel flow for one engine only, but it would adjust.If I test the number of engines with this:%((A:NUMBER OF ENGINES,number))%!2.0f!It shows 2I must be overlooking something.ThanksEDIT.If I use each engine, one at a time with this statement it displays the correct fuel flow for that engine. I changed the "A:Eng2" to read "A:Eng1", for the test. Using this example & format what do I need to do to add "Eng1", to the statement and end up with the total sum for both engines? %((A:Eng2 fuel flow GPH,gallons per hour))%!4.1f!%I have tried this statement and it only reports one engine.%((A:Eng2 fuel flow GPH,gallons per hour) (A:Eng1 fuel flow GPH,gallons per hour)+)%!4.1f!

Share this post


Link to post
Share on other sites

Here's the whole element: (A:NUMBER OF ENGINES, NUMBER) 2 == if{ (A:Eng2 fuel flow GPH,gallons per hour) (A:Eng1 fuel flow GPH,gallons per hour) + (>G:Var1) } els{ (A:Eng1 fuel flow GPH,gallons per hour) (>G:Var1) } %((G:Var1))%!4.1f!Doug

Share this post


Link to post
Share on other sites
Guest greenco

Doug, that piece of code (the whole element) worked just fine. Now I need to study it to find out just how it works and to try and spot the differences between your code and all of the code that I have tried. Right now I am going to give my "old" brain a rest and maybe look at it in a couple of days.I can't thank you enough!greenco

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