Table of Contents

Common available functions

Abs(Number) -> Number

Calculates the absolute value.

Abs(-2) = 2

Min(Number, Number) -> Number

Returns the minimum value of the two inputs.

Min(10, 3) = 3

Min(Number[]) -> Number

Returns the minimum value in an array of numbers.

Min([10, -3, 2]) = -3

Max(Number, Number) -> Number

Returns the maximum value of the two inputs.

Max(10, 3) = 10

Max(Number[]) -> Number

Returns the maximum value in an array of numbers.

Max([10, -3, 2]) = 10

Clamp(Number, min: Number, max: Number) -> Number

Clamps the number in the range between min and max.

Clamp(4, -10, 10) = 4
Clamp(-125, -10, 10) = -10

Round(Number) -> Number

Rounds the value to the nearest integer.

Round(12.45) = 12
Round(12.8) = 13

Ceiling(Number) -> Number

Rounds the value up to the nearest integer.

Ceiling(12.45) = 13
Ceiling(12.8) = 13

Floor(Number) -> Number

Rounds the value down to the nearest integer.

Floor(12.45) = 12
Floor(12.8) = 12

Fraction(Number) -> Number

Returns the fractional part of the number.

Fraction(12.45) = 0.45

Mod(Number, Number) -> Number

Returns the remainder when first argument is being divided by the second.

Mod(10, 3) = 1

Sign(Number) -> Number

Returns -1 for negative, 1 for positive and 0 for zero input.

Sign(5) = 1
Sign(0) = 0
Sign(-12) = -1

Sqrt(Number) -> Number

Returns the square root of the input.

Sqrt(16) = 4

Exp(Number) -> Number

Calculates the natural exponentiation of a given number.

Pow(Number, exponent: Number) -> Number

Raises the first argument to the power of the second argument.

Pow(2, 5) = 32

Log(Number) -> Number

Natural logarithm function.

Log(Number, base: Number) -> Number

Calculates logarithm in a given base.

ToDegrees(Number) -> Number

Converts radians to degrees.

ToRadians(Number) -> Number

Converts degrees to radians.

Sin(Number) -> Number

Trigonometric sin function. Input angle is in radians.

Cos(Number) -> Number

Trigonometric cos function. Input angle is in radians.

Tan(Number) -> Number

Trigonometric tan function. Input angle is in radians.

Asin(Number) -> Number

Trigonometric inverse sin function. Output angle is in radians.

Acos(Number) -> Number

Trigonometric inverse cos function. Output angle is in radians.

Atan(Number) -> Number

Trigonometric inverse tan function. Output angle is in radians.

Sum(Number[]) -> Number

Calculates the sum of elements in a vector or an array.

Sum([10, -3, 2, 5]) = 14

Length(Number[]) -> Number

Calculates the length of a vector.

Length([3, 4]) = 5

LengthSquared(Number[]) -> Number

Calculates the length squared of a vector. This is faster to calculate than the length in cases where the exact length value is not needed, like when comparing lengths of two vectors.

LengthSquared([2, 6]) = 40
LengthSquared([2, 6]) > LengthSquared([3, 4]) = true

Dot(Number[N], Number[N]) -> Number

Calculates the dot product of two vectors. The vectors must be the same length.

Dot([2, 3], [-1, 4]) = 10

Cross(Number[3], Number[3]) -> Number[3]

Calculates the cross product of two three-dimensional vectors.

Mix(number1: Number, number2: Number, amount: Number) -> Number

Linearly interpolates between number1 and number2 based on the amount (usually in range 0.0 - 1.0)

Mix(2, 10, 0.0) = 2
Mix(2, 10, 0.5) = 6
Mix(2, 10, 1.0) = 10

SmoothStep(min: Number, max: Number, x: Number) -> Number

Calculates the Hermite interpolation between two values.

Normalized(Number[N]) -> Number[N]

Normalizes a numeric vector.

Normalized([3, 4]) = [0.6, 0.8]

Distance(Number[N], Number[N]) -> Number

Calculates the distance between two points. The vectors must be the same length.

Distance([2, 3], [5, 7]) = 5

DistanceSquared(Number[N], Number[N]) -> Number

Calculates the squared distance between two points (avoids square root). The vectors must be the same length.

DistanceSquared([2, 3], [5, 7]) = 25

AngleBetween(Number[N], Number[N]) -> Number

Calculates the angle between two direction vectors in radians. The vectors must be the same length.

Quaternion functions

Quaternions are represented as four-number vectors in [x, y, z, w] order. All angles are in radians.

QuaternionMultiply(Number[4], Number[4]) -> Number[4]

Multiplies two quaternions to compose rotations. Inputs and output are normalized.

QuaternionMultiply(QuaternionRotateX(ToRadians(90)), QuaternionRotateY(ToRadians(90)))

QuaternionNormalize(Number[4]) -> Number[4]

Normalizes a quaternion to unit length.

QuaternionNormalize([0, 0, 0, 2]) = [0, 0, 0, 1]

QuaternionSlerp(Number[4], Number[4], amount: Number) -> Number[4]

Interpolates between two rotations using spherical linear interpolation. amount is usually in the range 0.0 - 1.0.

QuaternionSlerp([0, 0, 0, 1], QuaternionRotateZ(ToRadians(180)), 0.5)

QuaternionFromEuler(Number[3]) -> Number[4]

Converts Euler angles to a quaternion. The input is [pitchX, yawY, rollZ].

QuaternionFromEuler([ToRadians(90), 0, 0]) = QuaternionRotateX(ToRadians(90))

QuaternionFromAxisAngle(Number[3], angle: Number) -> Number[4]

Creates a quaternion from an axis and angle. The axis is normalized automatically.

QuaternionFromAxisAngle([0, 2, 0], ToRadians(90)) = QuaternionRotateY(ToRadians(90))

QuaternionRotateX(angle: Number) -> Number[4]

Creates a quaternion for a rotation around the X axis.

QuaternionRotateY(angle: Number) -> Number[4]

Creates a quaternion for a rotation around the Y axis.

QuaternionRotateZ(angle: Number) -> Number[4]

Creates a quaternion for a rotation around the Z axis.

Average(Number[]) -> Number

Calculates the arithmetic mean of a numeric array. Fails on empty input.

Average([2, 4, 6]) = 4

Range(start: Number, endInclusive: Number) -> Number[]

Generates a sequence of numbers with a default step of 1. End value is included if reachable exactly.

Range(1, 5) = [1, 2, 3, 4, 5]
Range(5, 1) = []

Range(start: Number, endInclusive: Number, step: Number) -> Number[]

Generates a sequence of numbers with a custom non-zero step. Direction must match step sign. End value is included if reached exactly.

Range(5, 1, -2) = [5, 3, 1]
Range(0, 1, 0.5) = [0, 0.5, 1]

Reverse(Type_T[N]) -> Type_T[N]

Reverses the order of elements in an vector or array.

Reverse([1, 2, 3]) = [3, 2, 1]
Reverse([100, true, "Text"]) = ["Text", true, 100]

Append(Type_T[N], Type_T) -> Type_T[N+1]

Appends a single element to the end of the vector.

Append([1, 2, 3], 4) = [1, 2, 3, 4]

Prepend(Type_T[N], Type_T) -> Type_T[N+1]

Adds a single element to the start of the vector.

Prepend([2, 3, 4], 1) = [1, 2, 3, 4]

Concat(Type_T[M], Type_T[N]) -> Type_T[M+N]

Concatenates two vectors.

Concat([1, 2], [3, 4]) = [1, 2, 3, 4]

Repeat(Type_T[N], times: Number) -> Type_T[N*times]

Repeats a whole vector a given non-negative number of times (fractional part is discarded).

Repeat([1, 2], 3) = [1, 2, 1, 2, 1, 2]

RepeatValue(Type_T, times: Number) -> Type_T[times]

Creates a new vector repeating a single value.

RepeatValue(5, 4) = [5, 5, 5, 5]
RepeatValue("Hi", 3) = ["Hi", "Hi", "Hi"]

Skip(Type_T[], count: Number) -> Type_T[]

Skips a number of elements from the start.

Skip([1, 2, 3, 4, 5], 2) = [3, 4, 5]

SkipLast(Type_T[], count: Number) -> Type_T[]

Skips a number of elements from the end.

SkipLast([1, 2, 3, 4, 5], 2) = [1, 2, 3]

Take(Type_T[], count: Number) -> Type_T[]

Takes up to count elements from the start.

Take([1, 2, 3, 4, 5], 3) = [1, 2, 3]

TakeLast(Type_T[], count: Number) -> Type_T[]

Takes up to count elements from the end.

TakeLast([1, 2, 3, 4, 5], 2) = [4, 5]

Slice(Type_T[], start: Number, length: Number) -> Type_T[]

Extracts a sub-range starting at index start with given length (both floored). Clamped to bounds.

Slice([10, 20, 30, 40, 50], 1, 3) = [20, 30, 40]

Count(Type_T[]) -> Number

Returns number of elements.

Count([10, 20]) = 2
Count([100, true, "Text"]) = 3
Count([]) = 0

Count(Type_T[], predicate: (Type_T) -> Boolean) -> Number

Returns the number of items for which the predicate lambda is truthy.

Count([1, 2, 3, 4], { it <= 2 }) = 2
Count([1, 2, 3, 4], { x => x > 2 }) = 2

Map(Type_T[N], transform: (Type_T) -> Type_R) -> Type_R[N]

Applies the lambda to each element and returns a new array of the same length.

Map([1, 2, 3], { x => x + 1 }) = [2, 3, 4]
Map(Connectors, { c => c.IsConnected }) = [true, false, true]

The shorthand juxtaposition syntax is equivalent:

[1, 2, 3]{ x => x + 1 } = [2, 3, 4]

FlatMap(Type_T[N], transform: (Type_T) -> Type_R[]) -> Type_R[]

Applies the lambda to each element, expects the lambda to return an array, and flattens the returned arrays into a single result.

FlatMap([1, 2, 3], { x => RepeatValue(x, 2) }) = [1, 1, 2, 2, 3, 3]
FlatMap([[1, 2], [3, 4, 5]], { it }) = [1, 2, 3, 4, 5]

Filter(Type_T[], predicate: (Type_T) -> Boolean) -> Type_T[]

Returns the items for which the predicate lambda is truthy.

Filter([1, 2, 3, 4], { it <= 2 }) = [1, 2]
Filter(this.Components, { component => component.PartType == "Door" })

Reduce(Type_T[], initial: Type_A, reducer: (Type_A, Type_T) -> Type_A) -> Type_A

Combines the array from left to right starting from the given initial accumulator value.

Reduce([1, 2, 3], 0, { acc, x => acc + x }) = 6

Reduce(Type_T[], reducer: (Type_T, Type_T) -> Type_T) -> Type_T

Combines the array from left to right using the first element as the initial accumulator.

Reduce([1, 2, 3], { acc, x => acc + x }) = 6

This overload requires a non-empty array.

IndexOf(Type_T[], Type_T) -> Number

Returns first index of a structurally equal value or -1 if not found.

IndexOf(["a", "b", "c", "b"], "b") = 1
IndexOf(["a", "b"], "x") = -1

Contains(Type_T[], Type_T) -> Boolean

Returns true if value exists in the vector.

Contains(["a", "b", "c"], "b") = true
Contains(["a", "b", "c"], "x") = false

IndexOfArray(Type_T[], Type_T[]) -> Number

Returns the first index where the second array appears as a contiguous subarray in the first array, or -1 if not found.

IndexOfArray(["a", "b", "c", "b", "c"], ["b", "c"]) = 1
IndexOfArray(["a", "b", "c"], ["b", "x"]) = -1

ContainsArray(Type_T[], Type_T[]) -> Boolean

Returns true if the second array appears as a contiguous subarray in the first array.

ContainsArray(["a", "b", "c", "b", "c"], ["b", "c"]) = true
ContainsArray(["a", "b", "c"], ["b", "x"]) = false

Any(Type_T[]) -> Boolean

Returns true if any element is truthy.

Any([0, "", false, 5]) = true
Any([0, "", false]) = false

Any(Type_T[], predicate: (Type_T) -> Boolean) -> Boolean

Returns true if the predicate lambda is truthy for at least one element.

Any([1, 2, 3], { x => x > 2 }) = true

All(Type_T[]) -> Boolean

Returns true if all elements are truthy.

All([1, "Hi", true]) = true
All([1, "", true]) = false

All(Type_T[], predicate: (Type_T) -> Boolean) -> Boolean

Returns true if the predicate lambda is truthy for every element.

All([1, 2, 3], { x => x > 0 }) = true

IsEmpty(Type_T[]) -> Boolean

Returns true if the vector has zero elements.

IsEmpty([]) = true
IsEmpty([1]) = false

PropertyValues(items: Type_T[N], propertyName: String) -> (items[propertyName])[N]

Maps an array of objects or records to the value of a single property on each item.

The propertyName argument must be a compile-time constant string.

If an item does not contain the requested property, or if the item does not support property access, the result contains null in that position instead of failing the script.

The result element type is inferred from the possible property types on the input items. If some items can produce no value for the requested property, null is included in the result type.

PropertyValues([PartA, PartB], "Name") = ["PartA", "PartB"]
PropertyValues(Connectors, "IsConnected") = [true, false, true]
PropertyValues([obj1, obj2, obj3], "MyProperty") = ["value1", null, "value3"]