ReferenceScripting APIUnits and values
Units and values
type labelsThe 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
| Name | What it is | A node's input of it, in Studio | When to use it |
|---|---|---|---|
Secondstype Seconds = number | A number of seconds. | A number marked s. | Durations, delays and times: anything a clock measures. A script has it without importing it. |
Degreestype Degrees = number | A number of degrees. | A number marked °. | Turns and angles. |
Pixelstype Pixels = number | A 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 = number | A number of pixels a second. | A number marked px/s. | Speeds in 2D, across the scene. |
Metrestype Metres = number | A number of metres. | A number marked m. | Distances in 3D: a 3D layer's world, and a 3D mote's place. |
MetresPerSecondtype MetresPerSecond = number | A number of metres a second. | A number marked m/s. | Speeds in 3D. |
Inttype Int = number | A 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> = number | A 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 = string | A colour, as words: "#rrggbb". | A colour, with a swatch to pick it. | Any colour. Colour is the name to use. |
Colortype Color = string | The same as Colour. | The same as Colour. | Only where code spelt the American way already has it. |
Layertype Layer = string | A 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 = Date | A date and time: a Date. | A date and time. | Calendars, alarms and countdowns. |
Exec<Names>type Exec<Names extends string> = Names | What 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) => void | A 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)
Notes from the community
Written by creators and checked by the docs' editors. Not part of Motion's official reference.