Profile image

[v. 1.9.202] - Funky Trees Explanation Addendum

66.6k SnoWFLakE0s  4.1 years ago

I’m currently in a elated state of mind as I write this. Simply an amazing new update for funky trees, lots of consistency fixes and new awesome features. I’ll go over the new changes and implications for the previous version of funky trees, but I’ll make sure to reiterate. Consider this an addendum for the now outdated old guide for the time being. In due time, I will either make a complete guide post or edit this guide to replace the old one.

WARNING: LONG POST


1. Data Type Organization Change

This is the most fundamental change for funky trees and lays the groundwork for a more organized system here on out. Here’s the text from the changelog:

Funky Trees now supports multiple types: Numbers (floating point), Booleans (true/false) and Strings (text). Values will be implicitly converted between these types if possible, for backwards compatibility, so a value of true will convert to 1 if used as if it was a number, and a value of false will be -1. New literals, "string", true, and false.

To explain, all usable data types in Funky Trees have now been organized into one of three categories- numbers, booleans, and strings. Here’s a rundown:

  1. Numbers are numbers including floats (e.g. 1, 1314, 12.0003, 0.334, etc).
  2. Booleans are very useful for logic. They are either true, or false. If you use them in conjunction with other data types, true or false can output the numbers 1 or -1 respectively. Previously in funky trees, booleans were inconsistent, this now has been fixed to be much more predictable.
  3. Strings are basically lines of text. They must be enclosed in quotations (“” marks). Strings may contain certain values.

Before I go through the changes, I first want to make sure that you understand what variables are in Funky Trees. Variables are special words that have a special value in Funky Trees. They contain data. The data type organization, in other words, is a way of organizing these variables into different types. The following is a list of all input variables:

Pitch, Roll, Yaw, Throttle, Brake, Trim, VTOL, LandingGear,
FireGuns, FireWeapons, LaunchCountermeasures, Activate1,
Activate2, Activate3, Activate4, Activate5, Activate6, Activate7,
Activate8, Altitude, AltitudeAgl, GS, IAS, TAS, Fuel, AngleOfAttack,
AngleOfSlip, PitchAngle, RollAngle, Heading, Time,
GForce, VerticalG, SelectedWeapon

We can now categorize these variables (their possible values included in parentheses):

NUMBER VARIABLES
  • Pitch (-1, 0, 1) / alternatively (-1~1) if joystick
  • Roll (-1, 0, 1) / alternatively (-1~1) if joystick
  • Yaw (-1, 0, 1) / alternatively (-1~1) if joystick
  • Trim (-1~1)
  • VTOL (-1~1)
  • Throttle (0~1)
  • Altitude - Aircraft's altitude in meters (-inf~inf)
  • AltitudeAgl - Aircraft's altitude above ground level in meters (-inf~inf)
  • GS - The speed relative to the ground (m/s) (0~inf)
  • IAS - The speed relative to the air, adjusted for the density of the air (m/s) (0~inf)
  • TAS - The speed relative to the air (m/s) (0~inf)
  • Fuel - The amount of fuel remaining as a proportion of capacity (0~1)
  • AngleOfAttack - The angle of attack (angle airflow vertically meets the boresight) in degrees (0~360)
  • AngleOfSlip - The horizontal equivalent of angle of attack (degrees) (-180~180)
  • PitchAngle - The pitch of the aircraft (degrees) (-180~180)
  • RollAngle - The roll of the aircraft (degrees) (-180~180)
  • Heading - The heading of the aircraft (degrees) (-180~180)
  • Time - The time since the level loaded (seconds) (0~inf)
  • GForce (omnidirectional "force" acting on the pilot, in g) (0~inf)
  • VerticalG (vertical component of G) (0~inf)

By far the most numerous, the numbers datatype contains variables that equate to the number class of variables. They’re conceptually easy to manipulate, but there are a great variety of number type variables and each has a unique range of values.
TL;DR: simply numbers, but everything is unique (requiring special attention from you).

BOOLEAN VARIABLES
  • Brake (true, false) or (1, -1)
  • LandingGear (true, false) or (1, -1)
  • FireGuns (true, false) or (1, -1)
  • FireWeapons (true, false) or (1, -1)
  • LaunchCountermeasures (true, false) or (1, -1)
  • Activate1 (true, false) or (1, -1)
  • Activate2 (true, false) or (1, -1)
  • Activate3 (true, false) or (1, -1)
  • Activate4 (true, false) or (1, -1)
  • Activate5 (true, false) or (1, -1)
  • Activate6 (true, false) or (1, -1)
  • Activate7 (true, false) or (1, -1)
  • Activate8 (true, false) or (1, -1)

Booleans were previously inconsistent in Funky Trees due to a couple errors. The system has been revamped completely, removing the root source of that error. Now, if you only use boolean statements independent of other data types, you will get the value true or false. If you use booleans in conjunction with other data types, they will automatically convert to 1 or -1 (true or false respectively).
TL;DR: All boolean data type variables return either true or false, or 1 or -1 depending on its usage. This makes these logically consistent.

STRINGS VARIABLES
  • SelectedWeapon (the name of the selected weapon, such as "Boom 50") (“string”)
  • x” (“x”)

The number of actual strings datatype variables is technically only one as of the time of writing. However, note the variable “x” - this just means, there are theoretically unlimited variety of strings that you can use. Whatever you make your string- be it “this string” or “that string”- these are all valid strings. Strings are largely useful for the ammo(“string”) function we’ll cover later.


2. Functions

There’s been no “revolutionary” change in the operating mechanism of functions in Funky Trees, but new types of functions have been added. The new data type organization system also applies for functions- in that functions have specific types of data they can accept. Let’s look at those. I’ll spare the explanation for now, but here’s all the functions in their respective categories.

NUMBER-BASED FUNCTIONS
  • abs(x) - The absolute (positive) value of x.
  • ceil(x) - x rounded up to an integer.
  • clamp(x, min, max) - x clamped between min and max.
  • clamp01(x) - Equivalent to clamp(x, 0, 1).
  • deltaangle(a, b) - The shortest angle delta between angles a and b in degrees.
  • exp(x) - Returns e raised to the power of x.
  • floor(x) - x rounded down to an integer.
  • inverselerp(a, b, x) - Calculates the linear parameter t that produces the interpolant value within the range [a, b].
  • lerp(a, b, t) - Linearly interpolates between a and b, by a proportion of t.
  • lerpangle(a, b, t) - Similar to lerp, but interpolates correctly when values pass 360 degrees.
  • lerpunclamped(a, b, t) - Similar to lerp, but doesn't clamp the value between a and b.
  • log(x, p) - The logarithm of x in base p.
  • log10(x) - Equivalent to log(x, 10).
  • pingpong(x, l) - "Ping-pongs" the value x so it is never larger than l and never less than 0.
  • max(a, b) - The largest value between a and b.
  • min(a, b) - The smallest value between a and b.
  • pow(x, p) - x raised to the power of p.
  • repeat(x, l) - Loops the value x so it is never larger than l and never less than 0.
  • round(x) - Rounds x to the nearest integer.
  • sign(x) - The sign of x (1 if x positive, -1 if x negative)
  • smoothstep(a, b, t) - Similar to lerp, but with smoothing at the ends.
  • sqrt(x) - The square root of x.
  • sin(x) - The sine of x (degrees)
  • cos(x) - The cosine of x (degrees)
  • tan(x) - The tangent of x (degrees)
  • asin(x) - The arc-sine of x (degrees)
  • acos(x) - The arc-cosine of x (degrees)
  • atan(x) - The arc-tangent of x (degrees)

Number based functions are the most conceptually simple. It takes inputs that would be classified under the ‘number’ data type, and outputs a ‘number’ data type. E.g. It might take the value 1 and output 0.2. Pretty simple right?
TL;DR: takes inputs that are numbers, and outputs numbers.

TIME-BASED FUNCTIONS
  • rate(x): the rate of change of x.
  • sum(x): the integration of x over time.
  • smooth(x, rate): the output follows x, but only at a maximum speed of rate units per second.
  • PID(target, current, p, i, d): A PID controller with the parameters p, i and d.

These functions are the meat of this update’s funky trees additions- these are functions that measure things with respect to time. In particular, the rate and sum functions are the FT equivalent of derivatives (d/dx) and integrals (?dx), which enables the creation of far advanced inputs. If your math is on the level to understand derivatives and integrals, then you don’t really need much explanation on what these will do.
TL;DR: takes numbers with respect to time, and outputs a number.

STRING-BASED FUNCTIONS
  • ammo("string"): the amount of ammo left for the string “someweaponname”. That is, whatever the name of your weapon is, is the string you want to input into “string”.

There’s currently only one string-based function- it’s the ammo() function. Since it takes a string as input, that also means that the input the ammo() can be a string-type variable- i.e. the SelectedWeapon variable.
TL;DR: takes string / string variable as input, outputs a number.


3. New operators

A heavily requested feature, and it's finally real.

New operators:
Comparison: "=", ">", ">=", "<=", "<"
Boolean Operators: "&" (and), "|" (or)
Ternary (selection) Operator: a ? b : c (essentially if a then b else c)

The comparison operators ouput a boolean value (true/false, 1/-1).
The boolean operators are basically logic gates. These also output a boolean value (true/false, 1/-1).
The selection operator is extremely useful. It's a "if statement"- if a, then b, if not a, then c. This allows for enormous flexibility when designing funky trees code. I'm kinda seeing potential for making working computers here in SimplePlanes. computerception.

To write any of these expressions, simply do A (operator) B. e.g., A < B will output a boolean value of true or false, and if put together with number values, e.g. (A < B) - 1, then if A < B is true (1) then the statement will ouput 0. (This is just an example of the syntax.)

Explanation for logic operators:

You have & (and), | (or), and a ? b : c.

For &:

true & true = true
false &true = false
true &false = false
false & false = false

For |:

true | true = true
false | true = true
true | false = true
false | false = false

For a ? b : c

true ? b : c = b
false ? b : c = c


4. Debugging Console

One of the most heavily requested features from FT enthusiasts was a debugging console- now it’s here in 1.9.202. Simply open the dev console, type DebugExpression "expression", where expression is a funky trees input, e.g. Time - 1. The console will display the value of that expression in real time.


5. activationGroup compatibility

Previously in funky trees, the use of inputs was limited to parts that have an inputController class of attributes. Now, you can use it on things that have an activationGroup attribute instead… that means stuff like detachers are now compatible with funky trees. activationGroup type parts will activate if the input is true, or 1.


  • I will update my guide and create a comprehensive tutorial that encompasses the entirety of funky trees soon, but that’s another beast on its own so it’ll take some time, so stay tuned.

Well, that’s about it for an explanation of the changes and new stuff for now. I’ll make a video soon to elaborate, hope this helps.

  • Log in to leave a comment
  • Profile image

    Awesome guide to start and I'm definitely staying tuned, thank you!

    3 months ago
  • Profile image

    How do I make it so my Switch 9 input starts/ spins my prop at a low rpm when turned on without it creating thrust till I throttle up and how to make it so it does so after a couple seconds after I turn the starter on?

    3 months ago
  • Profile image
    9,436 Mixx

    @Planemodder1911 use the if command/
    [INPUT] ? [TEXT] : [NO TEXT]

    4 months ago
  • Profile image

    How to make a text appear when I do an input?

    4 months ago
  • Profile image

    Do you know how to make it so when my switch ( switch13 ) is off and the red light turns on but when the switch13 is on the green light turns on and the red one turns off?

    And how to set simple throttle too a parking brake when pushed in?

    6 months ago
  • Profile image
    9,436 Mixx

    @Jusevs
    This'll turn itself off
    ((clamp01(Activate1)) - smooth((clamp01(Activate1)),0.1))

    This'll stay on until you switch it off
    (clamp01(clamp01(Activate1) + smooth(clamp01(Activate1) ,0.05)))

    +2 9 months ago
  • Profile image
    195 Polarity

    Would there be a way to send input to an engine to get thrust really quickly but lose it very slowly?

    9 months ago
  • Profile image

    how to connect pitch and angle of attack

    +1 10 months ago
  • Profile image

    i want to make rotators for a cannon so that it uses camera aim, after firing it returns to 0 for 2 seconds then returns to the point its aimed at

    10 months ago
  • Profile image

    i just want to play simpleplanes why i also have to coding
    im depressed now lol…

    10 months ago
  • Profile image

    nvm found it now time to see

    1.1 years ago
  • Profile image

    help i cant find on the command area to palce the commands

    1.1 years ago
  • Profile image

    Thanks this helped me a lot!

    1.2 years ago
  • Profile image

    @SnoWFLakE0s Thanks for the help, I read everything again and found out about clamp, messed around with it a bit and it works now! Thanks again :))

    1.7 years ago
  • Profile image
    66.6k SnoWFLakE0s

    @AlexyxD
    .
    abs() will make any value positive. Try it without the absolute value function

    1.7 years ago
  • Profile image

    Is there a way to activate flaps with only NEGATIVE VTOL? I tried abs(VTOL)<0 but it doesn't start on 0, it starts on 1(max)

    1.7 years ago
  • Profile image
    11.7k MRM19

    This is kind of an odd question, but since this is on the topic of the new update… can you possibly think of a way to have a lever automatically return to its zero position once an input has stoped being given?

    I am still relatively new to the XML/funky trees side of SP.

    Thank you

    -MRM19

    1.8 years ago
  • Profile image

    How would I display the currently selected weapon on the text block?

    +1 2.1 years ago
  • Profile image
    16.5k Mekomara

    i wonder if there is any way to make an "incoming missile" alert. The posts i founds about this are very old and a lot of new stuff added since.

    +1 2.1 years ago
  • Profile image
    11.9k X99STRIKER

    Me trying to understand this: confused unga bunga

    +2 2.1 years ago
  • Profile image

    @SnoWFLakE0s Thanks! Yours and PlaneFlightX's YouTube tutorials have helped a lot, but I'm about 2 years behind on learning FT, so my impatience begs me to ask sometimes :)

    2.2 years ago
  • Profile image
    66.6k SnoWFLakE0s

    @JamesDean
    .
    <color={a ? "FFFFFF" : "000000"}>
    White & black for an example. I'm sure you can infer from here on out

    +1 2.2 years ago
  • Profile image

    Is there a way to change the color of text-code dependent on the status of an input? Example, a ? b : c where a=ButtonPushedInput, b and c are color codes that make the text appear in a high-contrast color on the MFD

    2.2 years ago
  • Profile image
    1,456 Amirabadi

    can someone explain me about PID

    +1 2.5 years ago
  • Profile image

    How can I make my elevator compress at high speeds

    2.6 years ago
  • Log in to see more comments