Profile image

Funky Trees!

Dev WNP78  1.9 years ago

Andrew decided to call the new inputs system I cooked up "funky trees". Somehow escapes me why, but I'll roll with it. Here I'll describe what you can do in the land of funk.

Essentially what this means is that you can enter any mathematical expression (following this syntax) into an input field and it will be evaluated every frame. You can pull in data from a variety of sources, and process these how you like.


What you can now do is use the normal input axes:

  • Pitch
  • Roll
  • Yaw
  • Throttle
  • Brake
  • Trim
  • VTOL
  • LandingGear
  • FireGuns
  • FireWeapons
  • LaunchCountermeasures
  • Activate1
  • Activate2
  • Activate3
  • Activate4
  • Activate5
  • Activate6
  • Activate7
  • Activate8

Flight data

In addition to this you can access some information from the aircraft:

  • Altitude - Aircraft's altitude in metres
  • AltitudeAgl - Aircraft's altitude above ground level in metres
  • GS - The speed relative to the ground (m/s)
  • IAS - The speed relative to the air, adjusted for the desnity of the air (m/s)
  • TAS - The speed relative to the air (m/s)
  • Fuel - The amount of fuel remaining as a proportion of capacity (0 to 1)
  • AngleOfAttack - The angle of attack (angle airflow vertically meets the boresight) in degrees
  • AngleOfSlip - The horizontal equivalent of angle of attack (degrees)
  • PitchAngle - The pitch of the aircraft (degrees)
  • RollAngle - The roll of the aircraft (degrees)
  • Heading - The heading of the aircraft (degrees)
  • Time - The time since the level loaded (seconds)
  • GForce - The acceleration and gravitational "force" acting on the cockpit in G. I know it's not a force. Shut up.
  • VerticalG - The signed vertical component of the "G Force".
  • SelectedWeaponName - The name of the selected weapon
  • Latitude - The North/South position of the craft (metres)
  • Longitude - The East/West position of the craft (metres)
  • PitchRate - The pitch angular velocity in degrees/second
  • YawRate - The yaw angular velocity in degrees/second
  • RollRate - The roll angular velocity in degrees/second (these 3 inputs are better than using rate(PitchAngle) etc, because they account for wrapping around the angle, as well as being in local space: rate(Heading) is different to YawRate)
  • TargetSelected - true if a target is selected, else false.
  • TargetHeading - the heading to the selected target in degrees.
  • TargetElevation - the vertical angle to the selected target in degrees.
  • TargetDistance - the distance to the selected target in metres.


Values that are always the same:

  • pi the mathematical constant pi (half a tau, if you will).
  • e the mathematical constant e.
  • true a true boolean value
  • false a false boolean value


These are useful for... maths or something.

  • Mathematical:

    • +, - addition and subtraction (- can be used as a unary operator, for instance -Pitch

    • *, / multiplication and division

  • Comparison:

    • <, > less than, greater than

    • <=, >= less than or equal to, greater than or equal to

    • ==, != equal to, not equal to

  • Boolean:

    • &, AND

    • |, OR

    • !, NOT (this is a unary operator)

    • Ternary operator: condition ? value_if_true : value_if_false - this chooses between two values based on the condition.


Finally, there's some helpful functions to do maths for you!

  • abs(x) - The absolute (positive) value of x.
  • ammo(name) - The amount of ammo of the weapon with name. Remember to put the name in &quot; quotes.
  • 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)

Memory Functions

These are functions that are special because their output not only depends on inputs but their previous state.
- sum(x) - Returns the sum of all it's inputs over time (the integral of x)
- rate(x) - Returns the rate of change of x relative to its value last frame (the derivative of x)
- smooth(x, t) - When loaded, it's output is set to x. As x changes, the output tries to move to x, but at a rate of no greater than t. This is vaguely equivalent to changing the speed of a rotator.
- PID(target, current, p, i , d) - Evaluates a PID controller with the setpoint of "target", process variable "current" and the gains p, i, and d. Equivalent to: p * (target - current) + i * sum(target - current) - d * rate(current)

With all of these at your disposal, I'm excited to see what kind of contraptions you guys come up with, and I'm also open to some suggestions as to some things that could be added.

-WNP78, your funk master.

  • Log in to leave a comment
  • Profile image

    Is it possible to read the current RPM of a regular propeller engine with this?

    +3 yesterday
  • Profile image
    1,425 Nitsu

    @Awalters38 same

    3 days ago
  • Profile image
    1,740 Formula350

    @KyaRL People who make LUA scripts ("recipes" in the game) for the science game use this to calculate a "Random" number ("seed").
    Granted, it doesn't translate over to SP, it seems easily able to be SOMEWHAT replicated from what I see available (and I suck at FT and "recipe" coding!).

    while seed&lt;10000000 do seed=seed*10 end

    Perhaps something that does like...
    pingpong(Latitude, Longitude) * Time / log(Altitude, Fuel)
    Again, I am not a coder, or good at math, so I don't know if that will resolve into a number -- or how to even get the number, for that matter -- but it feels like it should be able to produce a fairly random as hell number... provided you aren't immediately checking for it at the time whatever you built spawns in.
    Though, while I feel the key there is using pingpong, I get the impression that using Longitude and/or Latitude might not work directly, without some further nested math, to ensure it is always a positive value. Just seems like pingpong will always be a fairly random result on its own, and then when factored with everything else, ensures that you end up with a random value. But again, getting that equation to not error AND THEN getting the value it spits out, is where you're on your own... :}

    +2 5 days ago
  • Profile image

    What do you do when you need to store a value, say the aircraft’s heading when the level begins

    6 days ago
  • Profile image

    so i need help what variable i have to use to make the engines start slower but still have the same speed?

    6 days ago
  • Profile image
    Dev WNP78

    @KyaRL there's no built in random number generator, you'll have to find a way to get random values from the environment or the craft, probably by taking some very precise measurement.

    7 days ago
  • Profile image
    3,031 KyaRL

    I feel like I'm missing something, but is there any way to generate a random number?
    for example, if you put something like "random(a,b)" then it would generate a random number between the values of a and b. for example, random(1,10), would output a random number between 1 and 10. Perhaps also a way to be able to set a certain amount of decimal points for the random number to be generated as well, so say with the same input of random(1,10), you could get 5.555, 5.5, or 5 depending on the number of decimal points you choose to round to.
    Is there a way to do this already? because I feel like I've missed something reading through this that could provide a way to do so...

    7 days ago
  • Profile image
    Dev WNP78

    @elia The pigpen has a built-in fly-by-wire system that uses the new variables system to keep the plane stable. The acro switch just makes the plane less stable and able to do more acrobatics.

    9 days ago
  • Profile image
    90 elia

    The official plane wasp has an acro function on it, it's something or a function that can i activate with funkytree or even by adding some hardware to every plane?

    9 days ago
  • Profile image
    9,909 poenix

    Hmm that would go pretty well with the smooth function. Now if only I can figure out how to make it work in increments @Dima0012m

    10 days ago
  • Profile image

    @poenix if you want the flaps to be used per button, here's the code:max(Activate2,0). if you want the flaps to be adjusted, add sliders there VTOL or roll etc.

    10 days ago
  • Profile image

    @poenix if you want the flaps to be used per button, here's the code:max(Activate2,0). if you want the flaps to be adjusted, add sliders there VTOL or roll etc.

    10 days ago
  • Profile image
    1,545 QinQianWen


    10 days ago
  • Profile image
    9,909 poenix

    Any ideas how I can set flaps to a button and have them cycle through the settings? I’m replicating a German design and the flaps are on push buttons that cycle between the different flap settings.
    +0.10 VTOL maybe?

    11 days ago
  • Profile image
    150 SirButter

    @Dima0012m Care to elaborate?

    12 days ago
  • Profile image

    @SirButter Well, at least there is something ... I make mechanisms even with such capabilities, and they are experimental.

    12 days ago
  • Profile image

    @SirButter Well, at least there is something ... I make mechanisms even with such capabilities, and they are experimental.

    +1 12 days ago
  • Profile image
    150 SirButter

    Hey all, I'm trying to get some inputs from some cockpit buttons and I was wondering how to get them to activate custom variables (trying to build a simple autopilot, buttons used to select altitude and heading). I can set a button to something like FireGuns and that works fine, but I don't want to use an existing variable (because they need to be available for their regular uses). Is it possible to do this? If not then that's a shame, that's really limiting on what inputs one can have with funky trees. Any advice appreciated!

    +2 13 days ago
  • Profile image

    @RYAviation yes, Its possible, Very Possible. Put * Activate [number] here like Throttle * Activate1

    +1 13 days ago
  • Profile image
    75 NATCH

    Hello guys i need some help, so i can put input on overload? Then things work magically?, i mean I'm not good any any fields about science and math but i wnat to learn this kind of things, if any one know someone who make or post a list of examples for beginners to do overloads can you please mention them, that will be very helpful

    13 days ago
  • Profile image

    So like I’m trying to get a two engine to turn on only if activation 1&2 , 1&3 are on is that even possible with funky

    19 days ago
  • Profile image

    Errr... could you please update the codes for the 1.11 update? Like, the missile lock codes or something like that?

    +2 19 days ago
  • Profile image
    922 Atrocitum

    @AlexRu да легко ими пользоваться. Для начала установи моды Overload и Fine tuner (есть в меню во вкладке mods). У тебя в редакторе появится кнопка, на которой изображен самолет, а над ним знак </>. При выборе любой детали самолета и нажатии на кнопку ты сможешь редактировать параметры этой детали и добавлять новые (например, масштаб, хп, влияние сопротивления воздуха, сила тяги для двигателей, время наведения, маневренность и угол захвата цели для самонаводящихся ракет и т.д.). Теперь переходим, собственно, к функциям. Разберем на примере ротатора. Открываешь меню overload, выбрав ротатор, заходишь во вкладку Input Controller и видишь параметр Input. Это условие для работы ротатора. Например,если Input = Pitch,то ротатор будет работать при команде с джойстика на отклонение руля высоты. Функции позволяют задать кастомное условие. Например, если условие на ротаторе GearDown, то он сработает, когда шасси будут полностью убраны. Это можно использовать, например, для создания кастомных створок шасси. А еще с помощью различных функций и их комбинаций можно заставить снаряд пушки взрываться рядом с целью. Или сделать автопилот, который наводить нос самолета на цель. Или потсроить турель с автонаведением. В общем, потннциал фактически огромен. Понятно, что сложные вещи требуют сложных функций, но сделать, допустим, отсеки с самонаводящимися ракетами , открывающиеся только если ракеты захватили цель, или кастомные шасси со створками не составит никакого труда, зато будет офигенно выглядеть и поможет набрать апвоутов.

    20 days ago
  • Profile image

    Are you able to use something like this random<5

    21 days ago
  • Profile image
    15 AlexRu

    Класс, так и не понял как пользоваться, но выглядит круто. Правда есть один вопрос— а с хрена ли записе два года? :/

    21 days ago
  • Log in to see more comments