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!
@TheFlightGuySP I tried getting it to work but i couldn't, thanks for trying to help me anyway.
@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.
@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
@Milo1628xa It depends on your needs. Let's say
b1 = if2
andc1 = if3
ina1 ? b1 : c1
.The code might look something like this:
You can also nest them like this:
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.
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?
@ToeTips It was for this thing.
@TheFlightGuySP
What does it do? Like the flight simulator?
@ToeTips Digital flight display on an abandoned project.
@TheFlightGuySP
What was the speed code used for?
@Blueshift No problem :)
@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 🙂
@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 :)
@TheFlightGuySP
hi, thanks for the prompt reply 👍🏼. can you show an example of what you mean?
@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.
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"?
@Redrocktumbler I'm assuming by 600 you mean 600m/s, in which case IAS>600 ? 0 : Input should do the trick.
@TheFlightGuySP How would I do this, but for control surfaces? Like disable above ias=600?
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.
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 ) ?
@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.
You should do one of these for PID controllers.
The *1 after throttle isn't necessary.