Trigger
One “when … happens, do this” rule: it pairs an event type (green flag, a key
press, a broadcast, a click, and so on) with the script that should run when
that event fires. A sprite’s triggers are how its scripts get started.
The Trigger engine class. Most members are available as free functions; this page documents the underlying API for advanced use.
BACKDROP_CHANGED
Section titled “BACKDROP_CHANGED”Trigger.BACKDROP_CHANGED: typeof Trigger.BACKDROP_CHANGEDTrigger type: fires when the stage’s backdrop changes.
Since 1.0.0
BROADCAST
Section titled “BROADCAST”Trigger.BROADCAST: typeof Trigger.BROADCASTTrigger type: fires when a matching broadcast message is received.
Since 1.0.0
CLICKED
Section titled “CLICKED”Trigger.CLICKED: typeof Trigger.CLICKEDTrigger type: fires when the sprite or stage is clicked with the mouse.
Since 1.0.0
CLICKED_OR_TAPPED
Section titled “CLICKED_OR_TAPPED”Trigger.CLICKED_OR_TAPPED: typeof Trigger.CLICKED_OR_TAPPEDFires for both mouse clicks and touch taps on a sprite/stage. The same
physical interaction (a tap on a touch device that the browser then
synthesizes a click for) only fires this trigger once.
Since 1.0.0
CLONE_START
Section titled “CLONE_START”Trigger.CLONE_START: typeof Trigger.CLONE_STARTTrigger type: fires when a clone of the sprite is first created.
Since 1.0.0
GREEN_FLAG
Section titled “GREEN_FLAG”Trigger.GREEN_FLAG: typeof Trigger.GREEN_FLAGTrigger type: fires when the green flag is clicked to start the project.
Since 1.0.0
KEY_PRESSED
Section titled “KEY_PRESSED”Trigger.KEY_PRESSED: typeof Trigger.KEY_PRESSEDTrigger type: fires when a specific key on the keyboard is pressed.
Since 1.0.0
LOUDNESS_GREATER_THAN
Section titled “LOUDNESS_GREATER_THAN”Trigger.LOUDNESS_GREATER_THAN: typeof Trigger.LOUDNESS_GREATER_THANTrigger type: fires when the microphone loudness rises above a value.
Since 1.0.0
TIMER_GREATER_THAN
Section titled “TIMER_GREATER_THAN”Trigger.TIMER_GREATER_THAN: typeof Trigger.TIMER_GREATER_THANTrigger type: fires when the timer rises above a value.
Since 1.0.0
TOUCH_END
Section titled “TOUCH_END”Trigger.TOUCH_END: typeof Trigger.TOUCH_ENDTrigger type: fires when a finger lifts off the sprite or stage.
Since 1.0.0
TOUCH_MOVE
Section titled “TOUCH_MOVE”Trigger.TOUCH_MOVE: typeof Trigger.TOUCH_MOVETrigger type: fires when a finger slides across the sprite or stage.
Since 1.0.0
TOUCH_START
Section titled “TOUCH_START”Trigger.TOUCH_START: typeof Trigger.TOUCH_STARTTrigger type: fires when a finger first touches the sprite or stage.
Since 1.0.0
Trigger.clone(): TriggerMakes a copy of this trigger with the same type, options, and script.
Since 1.0.0
Trigger.done: booleanWhether this trigger’s script has finished running.
Since 1.0.0
getGenerator
Section titled “getGenerator”Trigger.getGenerator(target: Sprite | Stage, args?: unknown[]): GeneratorCreates a fresh generator for this trigger’s script on a sprite so its steps can be advanced one at a time.
Since 1.0.0
isEdgeActivated
Section titled “isEdgeActivated”Trigger.isEdgeActivated: booleanWhether this trigger only fires on the moment a condition first becomes true (like the timer or loudness rising past a value), not continuously.
Since 1.0.0
matches
Section titled “matches”Trigger.matches(trigger: Trigger["trigger"], options: Trigger["options"] | undefined, target: Sprite | Stage): booleanChecks whether this trigger should fire for a given event type and options on a particular sprite or stage.
Since 1.0.0
option
Section titled “option”Trigger.option(option: string, target: Sprite | Stage): number | string | boolean | undefinedLooks up one of this trigger’s options for a sprite, running it as a function first if it was set up as one.
Since 1.0.0
Trigger.start(target: Sprite | Stage): Promise<void>Starts running this trigger’s script on a sprite, returning a promise that resolves when the script finishes or is stopped.
Since 1.0.0
Example
await myTrigger.start(this.sprite)Trigger.step(): voidRuns the script forward by one step, marking it done when it reaches the end.
Since 1.0.0
trigger
Section titled “trigger”Trigger.trigger: symbolThe trigger-type symbol that says what kind of event starts this script.
Since 1.0.0