Skip to content

Actions (Lua)

An Action is a short Lua script that moves things in a 3D Scene layer of the video monitor — bounce an object, spin the set, flash a light, push the camera in. You fire it live from the Action panel’s pads, for example during a performance or while you go On Air.

  1. Open Actions (Pre-production) and press New Action. Give it a name.
  2. Write the script in the editor (examples below).
  3. Press the save button (the disk icon, Save to assets/actions/). The script is saved to your space’s files as actions/<name>.lua — the name in lower case, spaces as dashes. Only saved actions reach the pads.

Import .lua and Export .lua move scripts in and out of the space.

Open the video monitor and show the Action panel. It has 16 pads, A to P. The space’s first 16 saved actions, in alphabetical order of their file names, sit on the pads; start the names with a number (01 Bounce, 02 Flash, …) to choose the order. Press a pad to run its action.

  • An action runs for 5 seconds from the press, whether or not the timeline is playing.
  • Pads are local: a press plays on your device only and is not saved in the project.
  • The action changes 3D Scene layers in the monitor. A script that names something the scene does not have does nothing to that layer.
  • The pads pick up a saved change the next time you press them.

Plinken runs your script about 60 times a second while the action is active. Each time, the script reads the moment it is at from ctx and returns the values to set this frame. It does not move anything itself and keeps nothing from one frame to the next: every value is worked out from the time.

-- Bounce the node "ball" twice a second, 0.5 high
local h = math.abs(math.sin(ctx.localTime * math.pi * 2))
return { set = { ["ball.position.y"] = 0.5 * h } }
ctx.localTimeseconds since the pad was pressed
ctx.regionProgress0 at the press, 1 at the end of the 5 seconds
ctx.regionDurationthe action’s length in seconds (5)
ctx.deltaseconds since the previous frame (0 on the first)
ctx.timethe timeline position in seconds
ctx.rng(seed)a random number from 0 to 1 for that seed — the same on every device; vary the seed to get new numbers
params.slotthe pad that fired it, "A" … "P"

A table with any of:

  • set — values to set, e.g. { ["camera.fov"] = 35 }
  • add — values to add to what is there, e.g. a camera shake on top of a camera move
  • mul — values to multiply what is there by

Each key names a thing and a property in the 3D scene:

KeyMeans
"<node>.position.x" (.y, .z)where a node of the scene’s model is, in scene units
"<node>.rotation.y" (.x, .z)its rotation, in radians (math.pi is half a turn)
"<node>.scale.x" …, "<node>.visible"its size; whether it shows
"root.…"the whole scene
"camera.position.z", "camera.fov", "camera.lookAt"the camera
"light.<name>.intensity", "light.<name>.color.r" …a light, by its name in the model

Node and light names are the names in the 3D model (the .glb file) the layer shows.

Spin the whole scene once over the action:

return { set = { ["root.rotation.y"] = ctx.regionProgress * 2 * math.pi } }

Flash the light called key and let it fade:

return { set = { ["light.key.intensity"] = 4 * (1 - ctx.regionProgress) } }

Push the camera in by 1, eased, on top of any other camera move:

local k = ctx.regionProgress
local eased = k * k * (3 - 2 * k)
return { add = { ["camera.position.z"] = -1.0 * eased } }

A camera shake that dies away:

local frame = math.floor(ctx.localTime * 30)
local amount = 0.05 * (1 - ctx.regionProgress)
return { add = {
["camera.position.x"] = (ctx.rng(frame) - 0.5) * amount,
["camera.position.y"] = (ctx.rng(frame + 1000) - 0.5) * amount,
} }

One script, two pads: pad A lifts higher than the others:

local lift = params.slot == "A" and 1.0 or 0.5
return { set = { ["ball.position.y"] = lift * ctx.regionProgress } }

Actions run in a sandbox, so a script behaves the same for everyone in the space:

  • The standard math, string and table libraries are there; require, load, files, the network and the operating system are not.
  • math.random is not available; use ctx.rng(seed).
  • A script that takes too long or uses too much memory in one frame is stopped for that frame.
  • Actions do not run Plinken commands (play, record, add tracks). The pl.… scripting of the desktop Plinken DAW is a different system and does not run here.

If an action does nothing, check the names against the 3D model and look for an error in the browser’s developer console.