Profile image

Funky Trees - IF Statements Explained:

27.8k TheFlightGuySP  2.4 years ago

Funky Trees (FT) has a lot of confusing and daunting components, one of which is the IF statement (also defined as the IF operator). So today, I will briefly explain and break down the IF operator.

The IF operator format is a ? b : c. It may be a bit daunting, but it's more simple than you may think.
Basically, the operator checks if the input a is true or false. If a is true, then the output b is given. However, if a is false, then the output c is given. (Note: the a input must be a Boolean (true/false) value.)

Here is an example: Throttle=1 ? Throttle+0.5 : Throttle. This is an engine booster code. In this scenario, the operator checks if Throttle is at 1 (100%). If Throttle=1, then the output Throttle+0.5 is given to add an extra 50% increase in power to the engine. However, if Throttle is less than 1, the output Throttle is given, which is just the normal throttle output. Larger expressions can be used for the a input if needed.

Do some testing and experimentation with the IF operator, and see what does and doesn't work. There are many more ways to use this than the one shown above.

Thoughts or suggestions? Let me know!

  • Log in to leave a comment
  • Profile image
    10.1k Milo1628xa

    @TheFlightGuySP I tried getting it to work but i couldn't, thanks for trying to help me anyway.

    7 days ago
  • Profile image

    @Milo1628xa Sorry for the late response, I'm not 100% sure but based purely on speculation, it might look something like this:

    (engineidletoggle * 0.001) + (thrustreverserinput = 0 ? (PID(ThrottleValue, TAS, 3.5, 0, 2.3) * !Activate8) : (Brake & AltitudeAgl<10 & GS<20))


    I'm a little rusty with FT as I haven't been playing a whole lot in recent months, apologies if this doesn't work.

    18 days ago
  • Profile image
    10.1k Milo1628xa

    @TheFlightGuySP i can't figure it out, perhaps i asked the question wrong...
    I'll give u some context: i"m trying to make my engine work in 3 scenarios: Throttle + 0.001 (to make it look like it's slowly spinning when in idle), (PID(ThrottleValue, TAS, 3.5, 0, 2.3) * !Activate8, which is autopilot's Throttle input and Brake & AltitudeAgl<10 & GS<20, to simulate full throttle when using Thrustreverser. I tried tinkering and whatnot but I aint no expert, i get stuck

    29 days ago
  • Profile image

    @Milo1628xa It depends on your needs. Let's say b1 = if2 and c1 = if3 in a1 ? b1 : c1.
    The code might look something like this:

    a1 ? (a2 ? b2 : c2) : (a3 ? b3 : c3)
    


    You can also nest them like this:

    a1 ? (a2 ? (a3 ? b3 : c3) : c2) : c1
    

    Hope this helps!
    Sorry for the outdated tutorial as well. It could definitely use some touchups. I might make a new one in the future.

    one month ago
  • Profile image
    10.1k Milo1628xa

    Hi guys, i got a question, i want to use the IF code for a project but i need 3 IF statements in one another, how would i type that?

    one month ago
  • Profile image

    @ToeTips It was for this thing.

    1.2 years ago
  • Profile image
    27.1k ToeTips

    @TheFlightGuySP
    What does it do? Like the flight simulator?

    1.2 years ago
  • Profile image

    @ToeTips Digital flight display on an abandoned project.

    1.2 years ago
  • Profile image
    27.1k ToeTips

    @TheFlightGuySP
    What was the speed code used for?

    1.2 years ago
  • Profile image

    @Blueshift No problem :)

    1.5 years ago
  • Profile image
    11.6k Blueshift

    @TheFlightGuySP thank you very much for your explanations. 👍🏼😎 Yes, I think I got it, will continue to work on my cockpit as soon as possible this weekend. Thank you & best regards 🙂

    1.5 years ago
  • Profile image

    @Blueshift Sure. Here's some code I pulled from a cancelled build:
    IAS<22.352 ? "LOW" : (TAS>111.76 ? "OVERSPEED" : round(IAS/0.44704)+"mph")

    The entire expression is basically a ? b : (a ? b : c).
    It checks to see if the speed is too low, and when it returns false then it checks to see if the speed is too high, and when that returns false it displays your IAS in mph.
    It was pulled from a text label, which is why it looks a bit different.
    You could also do a ? (a ? b : c) : c.

    Hopefully this helps :)

    +2 1.5 years ago
  • Profile image
    11.6k Blueshift

    @TheFlightGuySP
    hi, thanks for the prompt reply 👍🏼. can you show an example of what you mean?

    1.5 years ago
  • Profile image

    @Blueshift I don't believe so.
    You can achieve a similar result by putting an IF statement inside of another IF statement. It's a bit more complicated but its worked for me in the past.

    +2 1.5 years ago
  • Profile image
    11.6k Blueshift

    Hi All, question ?? is it possible to read more than "True" or "False" states with tertiary query? So, for example, reading out and evaluating very specific values ​​such as "Norm", "Idle-Start" and "Stop"?

    1.5 years ago
  • Profile image

    @Redrocktumbler I'm assuming by 600 you mean 600m/s, in which case IAS>600 ? 0 : Input should do the trick.

    +3 1.5 years ago
  • Profile image

    @TheFlightGuySP How would I do this, but for control surfaces? Like disable above ias=600?

    1.5 years ago
  • Profile image

    Hmm. The best answer I can give you is to view the FT guide: https://snowflake0s.github.io/funkyguide.html.
    It should cover all the major functions of FT that you will need to know.

    2.1 years ago
  • Profile image

    question: i use overloader on iphone, i will probably start building in ipad. with overloader i know how to change input to ft, but how would i word it? like with ( and ) ?

    2.1 years ago
  • Profile image

    @IICXLVIICDLXXXIIIDCXLVII I tried teaching myself PID to use on my Swift fighter jet.
    It was very time consuming and didn't work well.
    But, if I ever learn PID, I might do a tutorial on it.

    2.3 years ago
  • Profile image
    11.6k JesusChrist

    You should do one of these for PID controllers.

    2.3 years ago
  • Profile image
    49.5k PlaneFlightX

    The *1 after throttle isn't necessary.

    2.4 years ago