Skip to content

Triggers

A trigger is attached to a story, a challenge or an element and runs when a certain event happens in a session. A trigger can

  • run a script that sets a variable,
  • send a payload to a TotoObject,
  • lock or unlock a TotoObject.
{
"t": "OnElementSuccess",
"order": 1,
"script": { "parentId": "<variable id>", "expr": "{{d:keysFound}} + 1", "lang": "Javascript" },
"obj": { "objId": "<TotoObject id>", "payload": "open" },
"objLock": { "objId": "<TotoObject id>", "lock": true, "duration": 60 }
}
Field Meaning
t The event, see below.
order Order of execution among the triggers of the same event.
script Optional: parentId is the id of the variable that gets the result of the script expr.
obj Optional: send payload (a string) to the TotoObject objId.
objLock Optional: lock (lock: true) or unlock a TotoObject, optionally for duration.

Variable scripts run before payloads are sent, so payloads can use the new variable values.

Type Attached to Fires when Executed
OnStoryInitialize story the session is initialized ✅
OnStoryStart story the session is started ✅
OnChallengeRelease challenge the challenge is released ✅
OnChallengeFinish challenge the challenge is finished ✅
OnElementRelease element the element is released ✅
OnElementSuccess element the element is processed successfully (task solved, info acknowledged, choice made, dynamic processed, coin collected) ✅
OnElementError task, dynamic a wrong answer / the dynamic script failed ✅
OnElementSkip task the task was skipped ✅
OnElementRepeat element the player fired the manual trigger of the element ✅
OnStoryJoin story another player joined the session ❌ not executed
OnStoryFinish story the story was finished ❌ not executed
OnStoryCancel story the story was canceled ❌ not executed
OnObjectMessageReceived – a TotoObject sent a message ❌ not executed

The list of trigger types and whether they are executed is generated from the engine code: Trigger types.

Which triggers an element accepts depends on its type:

Element type Allowed triggers
Task OnElementRelease, OnElementSuccess, OnElementError, OnElementSkip, OnElementRepeat
Info OnElementRelease, OnElementSuccess, OnElementRepeat
Choice OnElementRelease, OnElementSuccess, OnElementRepeat
Dynamic OnElementRelease, OnElementSuccess, OnElementError, OnElementRepeat
Coin OnElementSuccess

All triggers caused by one action of the player are collected and executed sorted by type, in this order:

OnStoryInitialize → OnStoryStart → OnChallengeFinish → OnElementSuccess → OnElementError → OnElementSkip → OnChallengeRelease → OnElementRelease → OnElementRepeat

Triggers of the same type run in the order of their order field. Example: the player solves the last task of challenge C1, which releases challenge C2 with task T3:

  1. OnChallengeFinish of C1
  2. OnElementSuccess of the solved task
  3. OnChallengeRelease of C2
  4. OnElementRelease of T3

Because scripts run in this order, an OnElementRelease script already sees the variable values set by the OnElementSuccess scripts of the same step.

An element can have a manualTrigger: a button in its text that the player can press to run scripts and send object payloads again and again – e.g. “ring the bell”, “open the door”.

"manualTrigger": {
"max": 3,
"delay": 10000,
"scripts": [ { "parentId": "<variable id>", "expr": "{{d:bellRung}} + 1", "lang": "Javascript" } ],
"objects": [ { "objId": "<TotoObject id>", "payload": "ring" } ],
"objectLocks": []
}

max limits how often the player can press it per session (0 = unlimited), delay is the minimum time in milliseconds between two presses. The button is placed in the element text with the directive ::button[Ring the bell]{action="manualTrigger"} (see Content and Markdown). Each press fires the OnElementRepeat triggers of the element.