Motion
Get Motion

ReferenceScripting APIUnits and values

Units and values

type labels

The names that label a number or words with what they are (Metres, Seconds, Ranged<0, 1>), so a node's input in Studio shows its unit, takes whole numbers, or is a slider.

To a script these are plain numbers and words: a Metres is a number, a Colour a string, and anything takes one that takes the other. They're there for Studio. When a class's method is a node (@callable, in a scene's script or a pack of your own), each parameter is one of the node's inputs, and the type it's given says what that input is: a number marked in metres, a whole number, a slider. Import them from "motion" (Seconds is there without).

Units and values

NameWhat it isA node's input of it, in StudioWhen to use it
Secondstype Seconds = numberA number of seconds.A number marked s.Durations, delays and times: anything a clock measures. A script has it without importing it.
Degreestype Degrees = numberA number of degrees.A number marked °.Turns and angles.
Pixelstype Pixels = numberA number of the scene's pixels.A number marked px.Sizes and distances in 2D: on the scene, and a 2D mote's place.
PixelsPerSecondtype PixelsPerSecond = numberA number of pixels a second.A number marked px/s.Speeds in 2D, across the scene.
Metrestype Metres = numberA number of metres.A number marked m.Distances in 3D: a 3D layer's world, and a 3D mote's place.
MetresPerSecondtype MetresPerSecond = numberA number of metres a second.A number marked m/s.Speeds in 3D.
Inttype Int = numberA whole number.A number that takes whole numbers only.Counts, indexes and steps: anything that can't be a half.
Ranged<Lo, Hi>type Ranged<Lo extends number, Hi extends number> = numberA number from Lo to Hi.A slider from Lo to Hi.Amounts with a set range: Ranged<0, 1> for a mix, Ranged<-1, 1> for a balance.
Colourtype Colour = stringA colour, as words: "#rrggbb".A colour, with a swatch to pick it.Any colour. Colour is the name to use.
Colortype Color = stringThe same as Colour.The same as Colour.Only where code spelt the American way already has it.
Layertype Layer = stringA layer, by its name or id, as words.A pick of the scene's layers.An input that names a layer to change.
DateTimetype DateTime = DateA date and time: a Date.A date and time.Calendars, alarms and countdowns.
Exec<Names>type Exec<Names extends string> = NamesWhat a callable gives back to say which exec output goes on: one of Names.An exec output for each name; the one given back goes on.A node that branches: Exec<"Landed" | "Missed">.
Then<Values>type Then<Values extends unknown[]> = (...values: Values) => voidA function a callable is given, and calls.An exec output, fired each time it's called, with Values as its pins.A node that goes on more than once, or later: a loop's body, a timer.

Example

A node of your own, whose Height input is marked m, Strength a slider from 0 to 1, and Times a whole number:

import { Mote, Metres, Ranged, Int, callable } from "motion";export class Lantern extends Mote {    /** Lifts the lantern: its input says "m", and Strength is a slider. */    @callable({ category: "Garden" })    lift(height: Metres = 2, strength: Ranged<0, 1> = 0.5, times: Int = 1): void {        this.addOffset({ x: 0, y: height * strength * times, z: 0 });    }}

See also

Logic as code (classes, decorators and pins) · MotionPropertyOptions (a property's own unit and range, in Details)