Skip to main content

ScriptedInterpolator Protocol

Overview

ScriptedInterpolator is a runtime-backed protocol for custom interpolation behavior.

Runtime status

This protocol is validated against upstream runtime-v0.1.64 (b25a322) and tracked in the 2.37.6 runtime baseline audit (May 12, 2026).

Use it when linear interpolation is not enough and you need script-defined easing at the interpolation level.


Type Shape

export type ScriptedInterpolator<T> = {
init: ((self: T, context: Context) -> boolean)?,
transform: ((self: T, factor: number) -> number)?,
transformValue: ((self: T, valueFrom: number, valueTo: number, factor: number) -> number)?,
} & T

Optional methods

  • transform(self, factor) -> number
  • transformValue(self, valueFrom, valueTo, factor) -> number

Runtime fallback behavior

If a method is omitted or errors, runtime falls back to standard linear behavior.

  • Missing/failed transform -> returns original factor
  • Missing/failed transformValue -> uses from + (to - from) * factor

Template

export type MyInterpolator = {
strength: Input<number>,
}

function transform(self: MyInterpolator, factor: number): number
local t = math.max(0, math.min(1, factor))
return t * t
end

function transformValue(self: MyInterpolator, valueFrom: number, valueTo: number, factor: number): number
local t = transform(self, factor)
return valueFrom + (valueTo - valueFrom) * t
end

return function(): ScriptedInterpolator<MyInterpolator>
return {
transform = transform,
transformValue = transformValue,
strength = 1,
}
end

Exercise 1: Build a Quadratic Ease-In Mapper ⭐⭐

Premise

You are implementing interpolation math that should start slow and accelerate.

Starter Code

local function transform(factor: number): number
-- TODO: clamp to [0, 1], then return quadratic ease-in
return factor
end

local function transformValue(valueFrom: number, valueTo: number, factor: number): number
-- TODO: map transform(factor) across [valueFrom, valueTo]
return valueFrom
end

local result = transformValue(10, 30, 0.5)
print(string.format("ANSWER: %.1f", result))

Expected output

ANSWER: 15.0

Verify Your Answer

Verify Your Answer

Knowledge Check

Q:What happens if transformValue is not implemented in ScriptedInterpolator?

Next Steps