Check out the video guide here.
Table of Contents
- Inputs
- Math Operators
- Functions
- Syntax
- Practical Use
.
If you've understood how the new stuff works but just don't know how to use them ingame, then just only read sections 4 and 5.
.
I saw that lots of people were confused about how to use the input functions, which is why I've put this together. I've pretty much explained the stuff in the video, but here's a written guide for easier reference. I'll explain everything from the bottom-up, here we go:
1. Inputs
Remember math in school? Remember functions? Inputs are essentially the stuff you can put into a function- think the x
in f(x)
- and usually is the stuff you can change (x
is a variable).
.
There are largely two types of "inputs" you can use in SimplePlanes:
- User-controlled inputs, and
- Flight data inputs.
.
First, user-controlled inputs are self explanatory: you can control these inputs directly while playing. Here's a full list of all available user-controlled inputs (ignore the numbers for now):
- 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
- Throttle (0~1)
- Brake (0, 1)
- Trim (-1~1)
- VTOL (-1~1)
- LandingGear (-1, 1)
- FireGuns (0, 1)
- FireWeapons (0, 1)
- LaunchCountermeasures (0, 1)
- Activate1 (-1, 1)
- Activate2 (-1, 1)
- Activate3 (-1, 1)
- Activate4 (-1, 1)
- Activate5 (-1, 1)
- Activate6 (-1, 1)
- Activate7 (-1, 1)
- Activate8 (-1, 1)
Now, to explain the numbers- the numbers represent all the possible values that can be given to that input type. For example, Roll
has only -1, 0, and 1 as possible values: when you press on positive roll (D
in the game controls), you give the input type Roll
a value of 1. If you don't press on anything, it's given the default value of 0. If you press negative roll (A
in the game controls), you give the input type Roll
a value of -1. See where this is going?
There is an exception to this rule, which I will address below. Thanks to NavySealion for pointing it out.
.
There are also input types that don't have fixed values. For example, the input type Throttle
can be anything from 0 to 1 (represented in the list above as 0~1), which means it can be like 0.00001, 0.5324, 0.99992 etc. Just anything between 0 and 1. Visually, you can see this in the flight interface as the throttle is displayed to you as a percentage. Similarly, Trim
and VTOL
also are a range of values, except that these guys can range from -1 to 1. So a bit more flexibility, but the same sort of concept applies.
Now, there is a catch to the 'fixed' inputs examples I illustrated in the earlier paragraph. The fixed inputs only apply when you exclusively use keyboard controls. When you use a joystick or enable the mouse joystick option, the behavior of Roll
, Pitch
, and Yaw
change- they also become similar to VTOL / Trim
in that they now gain the ability to have a non-fixed input value. However, if you use keyboard controls only, they follow the fixed value rule (the first group of parentheses as possible values). The 'alternative' numbers in the parentheses illustrate the possible values if a joystick is used.
.
Second, the flight data inputs. These inputs are things you can't directly control, but still are able to be used as 'inputs' nonetheless. These all depend on the state of you aircraft (in SP, the state of your cockpit). Here's a full list of them below:
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 to 1) (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)
In a similar vein to that of the previous list, I've also pointed out all the possible values for each input type. Note that inf means infinity. As I've already explained the significance of the numbers, I'll talk about the next section:
2. Math Operators
Remember math in school again? Remember adding, subtracting, multiplying and dividing? and parentheses? PEMDAS? We can do that with SP now. Here's a list of all available Math Operators in SP (1.9 Beta):
+
: addition-
: subtraction*
: multiplication/
: division()
: parentheses to group statements (remember PEMDAS)
What can we do with these, you ask? You can use the inputs we covered above and the math operators in conjunction to form entirely new values. It's best illustrated with an example. Say that my input type Roll
value is set to 1 right now because I'm pressing on the positive roll button. I'm going to add some stuff to it. Let's say I want to create a final value of 5. I can add 4 to my current Roll
value to do that, right? Therefore: Roll + 4
, which would evaluate (result) in: (+1) + (+4) = +5. Wow! I have achieved a value of 5! If you know any basic maths at all, the rest of the math operators are used in similar fashion to the example I just illustrated.
.
Also one very important takeaway: whenever you use these math operators, make sure that you put a space before & after the operator. This is crucial because otherwise it creates a new input: Roll+1
signals an input type of 'Roll+1' to SP, while Roll + 1
equates to a statement of 'Roll plus 1'. Two very different things- it's an important distinction.
.
One final thing: we've also received pi
and e
as constants (fixed numerical values). If you don't understand what those two symbols mean, then you don't need to bother with them. Finally, onto functions:
3. Functions
Now is the time to jog your brain for actual school math: remember functions? All that f(x) and g(x) and stuff? Well, now it's in SimplePlanes, and you can use it to do cool stuff. Here's a list of the all the functions available as of 1.9:
- 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)
If you give a read to the explanation of each function, you should be able to get a pretty good idea of what each function does. These functions themselves are pretty useless, but combined with the inputs and math operators seen above, they can be used to do some cool stuff. For the sake of structure, I'll explain how to congregate everything you've just read about to do cool stuff:
4. Syntax
Now, you want to utilize everything you just saw to create some special stuff. The example I used in my video to explain is perhaps the best one to use particularly because it's very simple:
Remember the input type Roll
? We're going to work with that again. Remember, Roll
can have the values -1, 0, or 1. Now utilizing one of the functions listed in the functions section- let's try using the absolute value function, abs(x)
. Take a look at this: normally, if I just have Roll
, then if I press on negative roll, I give Roll
a value of -1, and therefore the final value is -1. However, if I use the absolute value function here- abs(Roll)
- then, even if I press on negative roll, giving Roll
a value of -1, the absolute value function will evaluate -1, giving out a value of +1, because that's what absolute value functions do. Therefore, abs(Roll)
where Roll
= -1 returns a value of abs(-1)
= +1.
.
Have you gotten the basic idea of how this stuff works? Let's go with a bit more complicated example. Let's look at this statement: abs(min(Roll, Pitch) * 2 + 1)
.
It's a bit complicated, but if you take a good look at it you can figure out how this works: SP will first take the smallest value between either Roll and Pitch. Then, it will multiply that value by 2, and add 1 to it. Finally, it'll take the absolute value of that.
In a numerical example, let's say that Roll
= 1, and Pitch
= -1. Then the following occurs: SP chooses the value -1 because it's the smallest value, then multiplies it by 2. Now we have -2, then SP adds + 1, therefore giving a value of -1. Finally, we take the absolute value of that, since abs(-1) = 1, our final value should return 1.
So, how do you utilize this inside SP? That's covered in the next section.
5. Practical Use
When you XML edit, you know that there is class of attributes labeled InputController
in XML. Under that class is usually an attribute called input
- this is where you add in your special statements. So, in the complicated example above, if I wanted that sort of functionality (whatever it is) in say, a rotator, then I'd go to the inputController
section of that particular rotator and just put in that special statement. In an in-line XML example, here's how you would write that in:
<InputController.State activationGroup="0" invert="false" min="-1" max="1" input="abs(min(Roll, Pitch) * 2 + 1)" />
.
Essentially the same is done if you're using Overload- just write the special statement in the entry field for input
. Pretty simple, right?
.
Now, I've left out one key part to how all this works- so I'll explain that now, since we've now covered every part of the input entry system. Okay. So, in SP, parts with special functions (wings, rotators etc.) all "act" (function) according to what I call their "perceived input", or the eventual, final output of the input statement. The perceived input used to be only one input type, such as Roll
, but with 1.9, now you can transform that perceived input in many ways using the math operators and functions. It's best to think of perceived input as a function in math, say, f(x) = x^2 + a. Here, the initial inputs are x and a, or in SP, things like the user-controlled inputs or flight data inputs. The perceived input, in the math function analogy, is the value of f(x). The parts in SP act only according to the perceived input, not anything else. It doesn't matter if you initial input is 3000- if your input statement is x - 3000, your perceived input becomes 0, and the part acts according to the perceived input value of 0.
.
For a practical example- let's say you have a bomb bay that's regulated by a single hinge part. You want this bomb bay to automatically open at an altitude of 3000 m. Now, if you set the hinge's input as something like Altitude - 2999
, then the moment you reach 3000m, your bomb bay should be fully open. Do you start seeing some pretty cool practical applications for this stuff?
Well, that's pretty much it- if you've managed to come this far, you should now have a pretty good understanding of how the new input system works. If you've any questions, feel free to ask. Thanks for reading.
.
Have fun, as always-
- SnoWFLakE0s
how do I make it so that when I'm at a certain IAS and altitude the text will glow
how to write code that i want this wing to be active at speed below 200 and inactive at speed above 200
What is wrong here? I just made an autoloader and I want it to be automatical so when I shot the piston would load gun but it doesnt happen.
The code is
floor(smooth(clamp01(FireWeapons), 1/1))
https://www.simpleplanes.com/a/zL25rA/Autoloadersimple
What should I do if I want to activate a control surface with an activation group so I can use it but while it’s off I can’t? Also what would I do if I want limited actuation on a rotator until an activation group is turned on and I get full motion?
@shipfinder568 Yes.
Excuse me, will pitch + roll will work so control surface will do elevon?
@SnoWFLakE0s Btw I'm working on something and I need a (Activate3 & TargetSelected & TargetDistance > 1625) to not turn off below 1625 I do not want the thruster to deactivate below 1625 just to where it will not activate below 1625 (like a safety) the only way I think it could be done is to make the Activate3 stick (once its activated it will not deactivate)
My brain hurt..
@WinsWings
.
Outdated. See the FT documentation for a up to date, more detailed document.
Well explained. Thanks for sharing
is there a funky trees code for a rotator?
heres what i want:
a code where a rotator only rotates half or less of the max angle example you have 20* of angle and i want it to rotate only 10* but i can make it rotate full by pressing an activation.
heres what i have:
clamp01(1-Activate1)*75)
but it doesn't work:/@airhermann
.
That is an archaic input type and not recommended for use.
@Hiistory you can set the speed v as an input. For example v</> something.
is there a way to make a helicopter follow your third person rotations this is the craft I'm currently trying to do this with
Is there a way where if I reach 260mph the propellers will start?
Brake input is wrong
the input is 0~1 not 0, 1
@sharpclaw this is already from the game itself, in version 1.12 or 1.11 you have these options...
What if you're on mobile and can't access any mods other than overload and the other one@Titaninfernal1
How do you make a stall warning light?
@sharpclaw First, set an input for the engine RPM using OUTPOST, I suggest using engine RPM1 , then try the following: "engine RPM1<500" Just substitute the value 500 for the value you want to activate the rotator, I think it will work
How do you make a light that turns on when your engine is rotating at more than The set Max RPM
hey @SnoWFLakE0s
I'm using an xbox controller and when put multiple inputs on a piston like 'Brake | Roll' both inputs seem to stop using the variable value that comes with joysticks, it just returns 1 for both brake and pitch instead of whatever value between -1, and 1 the stick is at. I know that Brake is a Boolean value input type, but I have been able to get brake to have joystick input type properties before when its just by itself like 'Brake'
Do you know of any way to make the inputs behave like they would when normally used on joysticks when using an |, OR operator?
@CatMouth32
Use the absolute value function. Or make your min value positive
@FurDynamicsweaponsandfirecontrol use finMode, and Static in overload
Hi, is there a way for the hinge rotator to only rotate in one way?