Skip to content
FREN

Expressions

The Expression node's language, its functions, and programs ready to paste.

The Expr node runs a small language over the telemetry. A program is one or more statements separated by ;, and the node grows the sockets it needs: a bare name becomes an input, $name = … declares an output, @channel reads a channel directly. Lesson 6 introduces it step by step.

The program below runs in the page with the code of the app’s Expr node. Move the revs: above 95% of the maximum, $on blinks; $col goes from green to red.

Grammar

Written What it is Example
name A name never assigned: an input, a socket to wire rpm / rpmMax
name = …; A variable of the calculation, no socket ratio = rpm / rpmMax;
@channel A game channel, read with no wire @gear, @speed_kmh
$name = …; An output: the only way to make one $shift = ratio > 0.95;
.x .y, .r .g .b .a The components of a vector, a colour (0 to 255) $dir.x = vel.x * 2

A fresh node starts with $out = value: replace it with your program. The editor colours the code and completes functions, constants and channels as you type.

Types

Each socket’s type comes from how a name is used, nothing to declare. Maths gives a number. .x or .y on a name makes it a vector; .r .g .b .a, or a name passed to mixcolor(), a colour. An output assigned from rgba() or mixcolor() is a colour; from text, "…", str() or format(), a text, to wire to a text widget. A comparison is worth 1 or 0.

Operators and constants

Maths: + - * / % ^; + joins as soon as one side is text, as in "P" + str(@position). Comparisons: == != < <= > >=. Logic: &&, ||, and !( … ): negation is written before a parenthesis. The choice cond ? a : b chains: g == 0 ? "N" : g == -1 ? "R" : str(g). Constants: PI and E.

Every function the Expr node accepts, taken from the app’s code: the list follows every release.

Math 13

min(a, b, …)
Smallest of the values.
max(a, b, …)
Largest of the values.
clamp(x, lo, hi)
Clamps x to [lo, hi].
abs(x)
Absolute value.
sign(x)
Sign: -1, 0 or 1.
floor(x)
Rounds down to the integer below.
ceil(x)
Rounds up to the integer above.
round(x)
Rounds to the nearest integer.
trunc(x)
Integer part (truncates toward zero).
fract(x)
Fractional part: x - floor(x).
sqrt(x)
Square root.
nth(k, c1, c2, …)
The rank of the k-th true condition, looping (0 when none): alarms that take turns.
countof(c1, c2, …)
How many conditions are true.

Trigonometry (radians) 9

sin(x)
Sine (radians).
cos(x)
Cosine (radians).
tan(x)
Tangent (radians).
asin(x)
Arc sine → radians.
acos(x)
Arc cosine → radians.
atan(x)
Arc tangent → radians.
atan2(y, x)
Angle of (x, y) → radians, handles quadrants.
deg(x)
Radians → degrees.
rad(x)
Degrees → radians.

Exponentials & logs 6

exp(x)
Exponential eˣ.
log(x)
Natural logarithm (base e).
log2(x)
Base-2 logarithm.
log10(x)
Base-10 logarithm.
pow(a, b)
a to the power b (same as a ^ b).
hypot(a, b, …)
√(a² + b² + …) — Euclidean length.

Interpolation 3

lerp(a, b, t)
Linear interpolation from a to b (t ∈ 0–1).
remap(x, inLo, inHi, outLo, outHi)
Re-maps x from [inLo, inHi] to [outLo, outHi].
smoothstep(lo, hi, x)
Smooth 0→1 transition as x crosses [lo, hi].

Colour 2

rgba(r, g, b, a?)
Builds a colour (0–255 components, optional alpha).
mixcolor(c1, c2, t)
Interpolates two colours (t ∈ 0–1).

Text 7

str(x)
Converts to text (concat via +).
format(x, decimals)
Formats a number with n fixed decimals.
timefmt(x, "m:ss.cc")
A time (s) as text in a real screen's pattern: m:ss.cc, mm:ss:cc, ±s.cc, h:mm:ss…
upper(text)
The text in capitals: upper(@session_type) gives “PRACTICE”.
lower(text)
The text in lower case.
shortname(text)
A driver's name in short, first initial and last name: shortname(@driver_ahead_name) gives “M. Verstappen”.
choose(i, v1, v2, …)
The i-th value of the list (1 = the first): one label per case.

State & time 16

prev(x)
Value of x at the previous tick.
changed(x)
true on the tick where x changes (either way).
rising(x)
true on the tick where x increases (rising edge).
falling(x)
true on the tick where x decreases (falling edge).
pulse(trig, dur_s)
true for dur_s seconds after a rising edge of trig.
elapsed()
Seconds elapsed (s) since the dashboard was shown.
since(trig)
Seconds since trig was last true (very large before that).
hold(trig, x)
x while trig is true, then the last value it held.
held(cond)
Seconds cond has been true without interruption (0 when false).
count(trig, reset?)
Number of rising edges of trig, back to 0 while reset is true.
toggle(trig, reset?)
Flips true / false on each rising edge of trig; reset sets it back to false.
latch(set, reset)
True once set is, until reset is (reset wins).
peak(x, reset?)
The maximum of x since the dashboard was shown or reset was last true (a braking peak).
low(x, reset?)
The minimum of x since the dashboard was shown or reset was last true (the apex speed).
avglast(x, n)
Average of the last n values of x, one per change, zeros skipped (last n laps).

State and time

prev, changed, rising, falling, pulse and blink remember the previous frame, like the Changed, Pulse and Blink nodes. Each call keeps its own state: two blink() in one program beat on their own. Time moves with the telemetry: game paused, timers frozen. A call in a ? : branch that isn’t taken keeps its state frozen, and picks up where it left off. elapsed() gives the seconds since the dashboard was shown.

Recipes

Programs to paste into the node, checked with the app’s code.

A shift light that flashes near the limiter
ratio = @rpm / 8000; $on = ratio > 0.95 ? blink(6) : 0; $col = mixcolor(rgba(0,255,0), rgba(255,0,0), smoothstep(0.7, 0.95, ratio))
The gear, with N and R
$g = @gear == 0 ? "N" : @gear == -1 ? "R" : str(@gear)
A 3 s warning on every flag change
$warn = pulse(changed(@flag_id), 3)
The delta is improving
$better = falling(@delta)
Fuel laps left, one decimal
$laps = format(@fuel_level / max(0.1, @fuel_used_per_lap), 1)
A rev counter needle's angle
$angle = lerp(-120, 120, clamp(@rpm / 8000, 0, 1))

Editor colours

In the node and in Properties, the editor colours each part of the code its own way: functions, numbers, texts, @ channels, $ outputs, components, constants, variables and operators. A typo shows before the error does.

What doesn’t get through

The language is closed: only the functions on this page run. Member and index access (a.b, a[0]), outside the .x .y .r .g .b .a components, names containing __ and a few reserved characters are refused, with a message in the node. An expression never reaches outside its node.