Skip to content
Docs
Reference

disko:expr

Presentation expressions every player's client evaluates each frame, for cameras, visuals, disc paint and HUD styles.

Import with import * as expr from "disko:expr". Generated from the module's shipped declarations. See Cameras & expressions for a guide.

disko:expr — presentation expressions: numbers and vectors a game declares once and every client evaluates on each frame it draws.

Expressions go wherever a presentation number or point is accepted: world.camera, world.visual and disc.setAppearance. They describe how presentation follows the drawn scene (a camera that follows the viewer, a ring that grows with speed, an opacity that pulses) and never affect game state.

The functions mirror disko:math: the same names mean the same things, but they return expressions instead of computing now. disko:math's two-word functions are one word here and accept vectors (lerpVector is lerp, scale is times). Import the module as a namespace, import * as expr from "disko:expr", so its names never clash with disko:math's; for example expr.lerp(expr.me.position, ball.position, 0.3) is the point 30% of the way from the viewer's disc to the ball.

Mistakes throw where they are made: TypeError for wrong kinds or argument counts, RangeError for non-finite numbers, naming the function.

Absence. A reference to something that doesn't exist on a frame (a destroyed disc, me for a spectator) makes the expressions that read it absent; so do invalid operations (sqrt of a negative number, clamp with min > max, normalize of a zero vector). or(a, b) picks b then. An absent camera falls back to the next camera for the viewer, then the default view; an absent visual number hides the visual for that frame; an absent disc paint number uses its default.

Limits: at most 256 nodes and 32 levels per expression, at most 16 arguments per variadic function.

Types

Expression

An expression; each client computes its value on every frame.

ts

NumberExpression

An expression producing a number.

ts

VectorExpression

An expression producing a vector.

ts

NumberLike

A finite number or a number expression.

ts

PointLike

A point whose coordinates are numbers or number expressions.

ts

VectorLike

A point or a vector expression.

ts

DiscReference

A disc as each client draws it.

ts
MemberDescription
positionCenter.
velocityVelocity in world units per tick.
xHorizontal center.
yVertical center.
radiusRadius.
speedLength of the velocity.

Constants

me

The viewer's own controlled disc; absent for spectators and in replays.

ts

time

Match time in seconds, interpolated; it stops while the match is paused.

ts

screen

The viewer's canvas in CSS pixels.

ts

Functions

disc

A disc as each client draws it. The disc must be live when the declaration using it is made; once destroyed, it is absent.

ts

plus

Sum of 2 to 16 numbers.

Sum of 2 to 16 vectors.

ts

minus

a - b for two numbers.

a - b for two vectors.

ts

times

Product of 2 to 16 numbers.

A vector scaled by one or more numbers.

ts

over

a / b.

A vector divided by a number.

ts

negate

The opposite number.

The opposite vector.

ts

min

Smallest of 2 to 16 numbers.

ts

max

Largest of 2 to 16 numbers.

ts

abs

Absolute value.

ts

floor

Largest integer not above the number.

ts

round

Nearest integer, halves away from zero.

ts

sqrt

Square root; absent for negative numbers.

ts

sin

Sine of radians.

ts

cos

Cosine of radians.

ts

clamp

value limited to [min, max]; absent when min > max.

ts

hypot

Length of (x, y).

ts

atan2

Angle of (x, y) in radians.

ts

lerp

a + (b - a) * t for two numbers.

a + (b - a) * t for two vectors.

ts

smoothstep

Smooth Hermite step from 0 to 1; absent when the edges are equal.

ts

remap

value mapped linearly from one range to another; absent when fromMin == fromMax.

ts

vec

A vector from two numbers.

ts

length

Length of a vector.

ts

distance

Distance between two points.

ts

dot

Dot product.

ts

midpoint

Point halfway between two points.

ts

normalize

Unit vector in the same direction; absent for the zero vector.

ts

rotate

A vector rotated by radians, as in disko:math (clockwise on screen).

ts

or

The first of 2 to 16 numbers that is present and finite.

The first of 2 to 16 vectors that is present and finite.

ts