api
The front door of scriptedEventsKit: define cues (trigger + ordered beats + rules), fire them, read the ledger, set flags, listen to events and extend the kit with your own beats and triggers. `local Cues = require("~scriptedEventsKit.api")`. Called by level scripts, scene entryp…
scriptedEventsKit.api
The front door of scriptedEventsKit: define cues (trigger + ordered beats + rules), fire them, read the ledger, set flags, listen to events and extend the kit with your own beats and triggers. local Cues = require("~scriptedEventsKit.api"). Called by level scripts, scene entrypoints, the Cue component and scaresKit. See the package README for every trigger, beat and event.
Interface
What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.
conforms to
zero/source-extract/v2nonstrict scriptedEventsKit.api: scripted events for level designers. `local Cues = require("~scriptedEventsKit.api")` Cues.define("lightsOut", { trigger = { kind = "area", entity = "hallTrigger" }, once = true, beats = { { "light", "hallLights", "short" }, { "wait", 2 }, { "show", "shape" }, { "sound", "sk_sting", at = "shape" }, }, }) A cue = a trigger (or a list of triggers, any of which fires it) + an ordered list of beats + rules (once | times = n | repeat with cooldown), conditions (`when`) and who it is for (`players`). The host decides every fire against one ledger that every peer mirrors, so a cue fires once for the world and a fired-once cue stays fired through death, respawn and rejoin for the whole session (and across sessions with a state store).
on(name: string, fn: any) → void
Listen for a scriptedEventsKit event on this peer: "cueFired" {id, by, count}, "beat" {id, index, kind}, "cueDone" {id}, "denied" {id, by, reason}, "flag" {name, value}, "reset" {id}. Returns a disconnect function.
| arg | type | description |
|---|---|---|
| name | string | |
| fn | any |
emit(name: string, data: any) → void
| arg | type | description |
|---|---|---|
| name | string | |
| data | any |
notify(name: string, data: any?) → void
Tell scriptedEventsKit a game event happened (feeds "event", "pickup", "interact" and "door" triggers): Cues.notify("pickup", { item = "fuse", peer = 1 }). Call it on the host, or anywhere for an event every peer sees.
| arg | type | description |
|---|---|---|
| name | string | |
| data | any? |
onNotify(name: string, fn: any) → void
| arg | type | description |
|---|---|---|
| name | string | |
| fn | any |
persist( ) → void
restore( ) → void
setStateStore(s: any?) → void
Keep the ledger (which cues fired, and flags) between sessions: { get = fn(key) -> value?, set = fn(key, value) }, or nil to stop. The host writes it after every fire.
| arg | type | description |
|---|---|---|
| s | any? |
useSaveKit( ) → boolean
Keep the ledger in saveKit's game data when saveKit is installed (soft link). Returns true when linked.
normTriggers(t: any) → void
| arg | type | description |
|---|---|---|
| t | any |
cleanupTriggers(id: string) → void
| arg | type | description |
|---|---|---|
| id | string |
define(id: string, spec: any) → string
Define (or redefine) a cue. spec: { trigger = {kind=...} | { {...}, {...} }, beats = { {"wait", 1}, ... }, once = true, times = n, ["repeat"] = true, cooldown = s, when = { flags = {..}, notFlags = {..}, after = {..}, notAfter = {..}, item = "name", test = fn(ctx) -> bool }, players = "trigger" | "all" | "near", near = metres, label, save = true, enabled = true }. Returns the id.
| arg | type | description |
|---|---|---|
| id | string | |
| spec | any |
undefine(id: string) → void
Forget a cue (its triggers stop; its ledger entry stays).
| arg | type | description |
|---|---|---|
| id | string |
get(id: string) → any
A cue's definition (normalized), or nil.
| arg | type | description |
|---|---|---|
| id | string |
list( ) → void
Every defined cue: { { id, label, triggers, beats = n, rule, fired } }.
setEnabled(id: string, on: boolean) → void
Turn a cue on or off (an off cue's triggers are ignored).
| arg | type | description |
|---|---|---|
| id | string | |
| on | boolean |
registerBeat(kind: string, fn: any, opts: any?) → void
Register a beat kind: fn(beat, ctx) -> seconds?. opts: { scope = "world" | "personal" | "host" | "time", main = field the 2nd entry fills, second = field the 3rd entry fills, desc }. ctx = { id, by, here, host, origin, players, spawned, data }.
| arg | type | description |
|---|---|---|
| kind | string | |
| fn | any | |
| opts | any? |
registerTrigger(kind: string, def: any) → void
Register a trigger kind (see scriptedEventsKit.triggers.register).
| arg | type | description |
|---|---|---|
| kind | string | |
| def | any |
register(name: string, fn: any) → void
Register a function the "call" beat runs by name, on every peer: fn(ctx, beat).
| arg | type | description |
|---|---|---|
| name | string | |
| fn | any |
registerSound(name: string, ref: any) → void
Let beats name a soundClip by a short name: Cues.registerSound("slam", asset.resolve("mygame.sounds.slam", "soundClip")).
| arg | type | description |
|---|---|---|
| name | string | |
| ref | any |
registerMaterial(name: string, ref: any) → void
Let spawn beats name a material by a short name.
| arg | type | description |
|---|---|---|
| name | string | |
| ref | any |
beatKinds( ) → void
Every beat kind: { kind, scope, desc }.
triggerKinds( ) → void
Every trigger kind: { kind, where, desc }.
setGate(fn: any?) → void
Install a gate the host asks before every fire: fn(cue, ctx) -> boolean (false vetoes it). nil removes it.
| arg | type | description |
|---|---|---|
| fn | any? |
flag(name: string) → any return ledger
A flag's value (nil when unset).
| arg | type | description |
|---|---|---|
| name | string |
flags( ) → any return table
Every flag: a copy.
applyFlag(name: string, value: any) → void
| arg | type | description |
|---|---|---|
| name | string | |
| value | any |
setFlag(name: string, value: any?) → void
Set a flag for the world (sent to every peer; the host keeps it). value defaults to true; nil clears it.
| arg | type | description |
|---|---|---|
| name | string | |
| value | any? |
fired(id: string) → number return ledger
How many times a cue has fired this session (or in the store).
| arg | type | description |
|---|---|---|
| id | string |
hasFired(id: string) → boolean return
Whether a cue has fired at least once.
| arg | type | description |
|---|---|---|
| id | string |
isRunning(id: string) → boolean
Whether a cue's beats are playing on this peer.
| arg | type | description |
|---|---|---|
| id | string |
applyReset(id: string) → void
| arg | type | description |
|---|---|---|
| id | string |
reset(id: string) → void
Forget that a cue fired (for testing), on every peer and in the store.
| arg | type | description |
|---|---|---|
| id | string |
resetAll( ) → void
Forget every fire and every flag (for testing), on every peer and in the store.
stop(id: string) → void
Stop a cue's beats that are still playing on this peer (they stop at the next beat).
| arg | type | description |
|---|---|---|
| id | string |
hasItem(peer: number, item: string) → boolean
| arg | type | description |
|---|---|---|
| peer | number | |
| item | string |
list(v: any) → void
| arg | type | description |
|---|---|---|
| v | any |
whyNot(id: string, by: number?, force: boolean?) → string
Why a cue would not fire now for player `by` (nil = it would).
| arg | type | description |
|---|---|---|
| id | string | |
| by | number? | |
| force | boolean? |
playersFor(c: any, by: number, origin: any) → any
| arg | type | description |
|---|---|---|
| c | any | |
| by | number | |
| origin | any |
decide(id: string, by: number, origin: any, force: boolean?) → void
| arg | type | description |
|---|---|---|
| id | string | |
| by | number | |
| origin | any | |
| force | boolean? |
fire(id: string, opts: any?) → boolean
Ask for a cue to fire, as player `by` (default: this peer's player). opts: { force = true (skip rules and conditions), at = origin point }. The host decides; from any other peer this is a request. Returns true when this peer decided and it fired.
| arg | type | description |
|---|---|---|
| id | string | |
| opts | any? |
isHere(players: any) → boolean
| arg | type | description |
|---|---|---|
| players | any |
runCue(id: string, by: number, seq: number, startAt: number, players: any, origin: any, count: number?) → void
| arg | type | description |
|---|---|---|
| id | string | |
| by | number | |
| seq | number | |
| startAt | number | |
| players | any | |
| origin | any | |
| count | number? |
playBeats(list: { any }, opts: any?) → any
Play a list of beats on THIS peer only, with nothing sent over the network (every peer that should see them calls it, e.g. from a "call" beat or a director slot). opts: { id, by, players = "all" | {peers}, origin, data, onDone }. Scopes still apply: personal beats only where `players` includes this peer, host beats only on the host. Returns a handle { cancel() }.
| arg | type | description |
|---|---|---|
| list | { any } | |
| opts | any? |
cancel( ) → void
go( ) → void
hookNet( ) → void
trigApi(id: string) → any
| arg | type | description |
|---|---|---|
| id | string |
hit(peer: number, origin: any?) → void
| arg | type | description |
|---|---|---|
| peer | number | |
| origin | any? |
playTime( ) → void
_firedAtLocal(cid: ?) → void
| arg | type | description |
|---|---|---|
| cid | ? |
_standIn(peer: ?) → void
| arg | type | description |
|---|---|---|
| peer | ? |
setupTriggers(id: string) → void
| arg | type | description |
|---|---|---|
| id | string |
_setStandIn(peer: number, e: any?) → void
Tests: let a stand-in body act as player `peer` for local triggers on the host.
| arg | type | description |
|---|---|---|
| peer | number | |
| e | any? |
ensureRunner( ) → void
Make sure this peer's runner exists (play mode). Called by define and by the Cue component.
_start( ) → void
The runner started: play began on this peer.
_stop( ) → void
The runner ended (play stopped): forget this session's ledger and triggers.
playTime( ) → number return getTime
Seconds since play started on this peer.
setDebug(on: boolean) → void
Draw every area / proximity trigger volume in play too (always drawn in edit by the Cue component).
| arg | type | description |
|---|---|---|
| on | boolean |
debug( ) → boolean return debugDraw end
_tick(dt: number) → void
One frame (the runner calls it).
| arg | type | description |
|---|---|---|
| dt | number |
_lateTick( ) → void
After the camera has turned this frame (the runner calls it).
_wantRunner( ) → void
Sub-parts
Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.
Showing up to 3 levels deep. Open a part to see what it holds further down.
Problems
Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.
agent_score is exposed.+ quality × 0.35
+ performance × 0.25
± compat factor
Usability ratings
Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".
Scoped to this part · feeds back into the world's score.