Skip to content

Tutorial: The Clockmaker's Key

This tutorial builds a complete city rally with the Toto API. Every request shown here was executed against the backend and the game was played through on all of its paths. It uses every element type, several solution types, variables in all three scopes, triggers, a dynamic element and conditional content.

The story: the clockmaker who looks after the World Clock at Alexanderplatz has lost the key that winds it. Players find the three pieces of the key around the square and wind the clock again.

Story "the-clockmakers-key" languages: eng, deu area: alexanderplatz coins: golden-gear, silver-gear
│
├── Challenge "the-world-clock"
│ welcome (Info) → reach-the-world-clock (Task: geofence) → time-zones (Task: multiple choice)
│
├── Challenge "two-ways"
│ which-way (Choice) ─┬→ tower-height (Task: free text) ─┬→ second-piece (Info, conditional text)
│ └→ church-photo (Task: user input) ─┘
│
└── Challenge "finale"
fountain-rivers (Task: free text, skippable) → check-the-key (Dynamic)
─┬→ golden-ending (Info) ─┬→ wind-the-clock (Task: QR code)
└→ ending (Info) ────────┘
Variable Scope Changed by
keysFound Session +1 on success of time-zones, tower-height, church-photo, fountain-rivers
gamesFinished Account +1 on success of wind-the-clock
clocksWound Repo +1 on success of wind-the-clock

check-the-key sends players with three pieces to the golden ending; players who skipped the river task have two pieces and get the normal ending.

In the requests below E is /v2/edit/{repoId}, texts are shortened to English; the real game has English and German translations for every text (see Content).

Upload the images and keep their ids:

PUT E/file
Content-Type: multipart/form-data; boundary=…
--…
Content-Disposition: form-data; name="file"; filename="world-clock.png"
…
POST E/area { "name": "world-clock" }
PUT E/area/{areaId}
{
"name": "world-clock",
"locations": [ { "lat": 52.52157, "lon": 13.41285 }, { "lat": 52.52157, "lon": 13.41365 },
{ "lat": 52.52107, "lon": 13.41365 }, { "lat": 52.52107, "lon": 13.41285 } ],
"content": { "title": [{ "lang": "eng", "text": "World Clock" }], "description": [],
"strokeColor": "#f2a541", "strokeOpacity": 0.9, "strokeWeight": 3, "fillColor": "#f2a541", "fillOpacity": 0.2 }
}

The second area alexanderplatz is a larger polygon around the square, used as play area of the story.

POST E/var { "name": "keysFound", "scope": "Session", "t": "Number", "defaultValue": "0" }
POST E/var { "name": "gamesFinished", "scope": "Account", "t": "Number", "defaultValue": "0" }
POST E/var { "name": "clocksWound", "scope": "Repo", "t": "Number", "defaultValue": "0" }

Create every element with POST E/element { "name", "t" }, then update it with the full element. content below contains only the fields that are not empty; the other content fields (publicInfo, postDescription, choiceDescription, successMessage, errorMessage, files) are sent as empty lists.

Info welcome

{ "name": "welcome", "score": 0, "solutions": {}, "trigger": [], "metaTags": [],
"content": { "title": [{ "lang": "eng", "text": "The clockmaker needs your help" }],
"description": [{ "lang": "eng", "text": "The old clockmaker who looks after the **World Clock** has lost the key …" }],
"logo": "<file id of story-cover>" } }

Task reach-the-world-clock – geofence

{ "name": "reach-the-world-clock", "score": 5, "trigger": [], "metaTags": [],
"content": { "title": [{ "lang": "eng", "text": "Go to the World Clock" }], "…": "…" },
"solutions": { "geofence": { "areaId": "<id of area world-clock>", "event": "Enter" } },
"location": { "showOnRelease": true, "gps": { "lat": 52.52132, "lon": 13.41325 }, "address": "Alexanderplatz, World Clock", "description": [] } }

Task time-zones – multiple choice, increments keysFound

{ "name": "time-zones", "score": 10, "metaTags": [],
"solutions": { "mc": { "choices": [ { "value": "12", "isCorrect": false, "score": 0 },
{ "value": "24", "isCorrect": true, "score": 10 },
{ "value": "36", "isCorrect": false, "score": 0 } ] } },
"trigger": [ { "t": "OnElementSuccess", "order": 1,
"script": { "parentId": "<id of keysFound>", "expr": "{{d:keysFound}} + 1", "lang": "Javascript" } } ],
"content": { "…": "…" } }

Choice which-way and its options – the label of each option is its choiceDescription

{ "name": "which-way", "score": 0, "solutions": {}, "trigger": [], "metaTags": [],
"content": { "title": [{ "lang": "eng", "text": "Two ways" }],
"description": [{ "lang": "eng", "text": "The TV Tower or St. Mary's Church – where do you want to look?" }] } }
{ "name": "tower-height", "score": 10, "metaTags": [],
"content": { "title": [{ "lang": "eng", "text": "At the TV Tower" }],
"choiceDescription": [{ "lang": "eng", "text": "The TV Tower" }], "…": "…" },
"solutions": { "text": { "ignoreCase": true, "choices": ["368", "368 m", "368m"], "score": 10 } },
"trigger": [ { "t": "OnElementSuccess", "order": 1,
"script": { "parentId": "<id of keysFound>", "expr": "{{d:keysFound}} + 1", "lang": "Javascript" } } ] }
{ "name": "church-photo", "score": 10, "metaTags": [],
"content": { "title": [{ "lang": "eng", "text": "At St. Mary's Church" }],
"choiceDescription": [{ "lang": "eng", "text": "St. Mary's Church" }], "…": "…" },
"solutions": { "input": { "textRequired": false, "imageRequired": true, "operatorRequired": false,
"textEnabled": true, "imageEnabled": true, "maxChars": 280 } },
"trigger": [ "… same as tower-height …" ] }

Info second-piece – shows a variable and conditional content

You have found **:variable[keysFound]{numberDecimals="0"}** pieces of the key so far.
![if][{{d:keysFound}} >= 2]
Only one piece is missing – it is near the Neptune Fountain.
![else]
Two pieces are still missing, but the clockmaker knows where to look next: the Neptune Fountain.
![endif]

Task fountain-rivers – free text, skippable after 120 s

"solutions": {
"text": { "ignoreCase": true, "choices": ["Rhine", "Rhein", "Elbe", "Oder", "Vistula", "Weichsel"], "score": 10 },
"skip": { "after": 120000, "score": 0,
"buttonLabel": [{ "lang": "eng", "text": "Skip" }],
"skipMessage": [{ "lang": "eng", "text": "No problem – the clockmaker gives you a hint …" }] }
}

Its OnElementSuccess trigger increments keysFound; skipping does not (skipping runs OnElementSkip).

Infos golden-ending and ending, Task wind-the-clock – QR code, updates the account and repository counters

{ "name": "wind-the-clock", "score": 10, "metaTags": [],
"solutions": { "secret": { "value": "CLOCKWORK" } },
"trigger": [
{ "t": "OnElementSuccess", "order": 1, "script": { "parentId": "<id of gamesFinished>", "expr": "{{d:gamesFinished}} + 1", "lang": "Javascript" } },
{ "t": "OnElementSuccess", "order": 2, "script": { "parentId": "<id of clocksWound>", "expr": "{{d:clocksWound}} + 1", "lang": "Javascript" } } ],
"content": { "…": "…" } }

These counters are on the last element because story triggers like OnStoryFinish are not executed.

Dynamic check-the-key – updated after the endings exist, because its script returns their ids

{ "name": "check-the-key", "score": 0, "solutions": {}, "trigger": [], "metaTags": [],
"content": { "title": [{ "lang": "eng", "text": "Does the key fit?" }], "…": "…" },
"script": { "expr": "{{d:keysFound}} >= 3 ? \"<id of golden-ending>\" : \"<id of ending>\"",
"lang": "Javascript", "solvedOn": ["<id of golden-ending>", "<id of ending>"],
"buttonLabel": [{ "lang": "eng", "text": "Put the pieces together" }],
"autoCheck": true, "errorMessage": [], "nothingMessage": [] } }

Coins golden-gear and silver-gear – type Coin, collected with the secrets GEAR-1 and GEAR-2:

{ "name": "golden-gear", "score": 25, "trigger": [], "metaTags": [],
"solutions": { "secret": { "value": "GEAR-1" } }, "content": { "…": "…" } }
POST E/challenge { "name": "finale" }
PUT E/challenge/{challengeId}
{
"name": "finale", "trigger": [], "metaTags": [],
"content": { "title": [{ "lang": "eng", "text": "Finale at the Neptune Fountain" }], "description": [],
"publicInfo": [], "files": [], "postDescription": [] },
"graph": {
"start": ["n1"], "finishedOn": ["n5"],
"nodes": [ { "id": "n1", "refId": "<fountain-rivers>", "posX": 0, "posY": 0 },
{ "id": "n2", "refId": "<check-the-key>", "posX": 0, "posY": 140 },
{ "id": "n3", "refId": "<golden-ending>", "posX": -150, "posY": 280 },
{ "id": "n4", "refId": "<ending>", "posX": 150, "posY": 280 },
{ "id": "n5", "refId": "<wind-the-clock>", "posX": 0, "posY": 420 } ],
"links": [ { "source": "n1", "target": "n2" }, { "source": "n2", "target": "n3" }, { "source": "n2", "target": "n4" },
{ "source": "n3", "target": "n5" }, { "source": "n4", "target": "n5" } ]
}
}

the-world-clock and two-ways are built the same way (two-ways: which-way → tower-height / church-photo → second-piece, finished on second-piece).

POST E/story { "name": "the-clockmakers-key" }
PUT E/story/{storyId}
{
"name": "the-clockmakers-key", "metaTags": [], "trigger": [],
"multiplayer": false, "supportedLanguages": ["eng", "deu"],
"associatedElements": ["<golden-gear>", "<silver-gear>"],
"area": "<id of area alexanderplatz>", "areaRestricted": false,
"content": { "title": [{ "lang": "eng", "text": "The Clockmaker's Key" }],
"description": [{ "lang": "eng", "text": "A city rally around Alexanderplatz …" }],
"publicInfo": [{ "lang": "eng", "text": "About 60 minutes, suitable for families. Start at the World Clock." }],
"procedures": [], "files": [], "logo": "<file id of story-cover>" },
"graph": { "start": ["s1"], "finishedOn": ["s3"],
"nodes": [ { "id": "s1", "refId": "<the-world-clock>", "posX": 0, "posY": 0 },
{ "id": "s2", "refId": "<two-ways>", "posX": 0, "posY": 120 },
{ "id": "s3", "refId": "<finale>", "posX": 0, "posY": 240 } ],
"links": [ { "source": "s1", "target": "s2" }, { "source": "s2", "target": "s3" } ] }
}
POST E/voucher { "name": "demo", "storyId": "<storyId>", "maxCount": 10, "sessionVarValues": [] }

GET E/voucher/search?storyId=<storyId> returns the voucher with its token.

Played with a player account (session cookie). Each step lists the elements the response contains:

Request Result
POST /v2/session/init { "token": "<voucher token>", "lang": "eng" } session created
POST /v2/session/{id}/start welcome released
info/acknowledge welcome reach-the-world-clock released
task/solve/geofence at 52.52132, 13.41325 time-zones released
task/solve/mc "24" which-way released, keysFound = 1
GET choice/{which-way}/options “The TV Tower”, “St. Mary’s Church”
choice/choose tower-height tower-height released
task/solve/text "368" second-piece released, keysFound = 2
info/acknowledge second-piece fountain-rivers released (challenge finale)
task/solve/text "elbe" check-the-key released, keysFound = 3
dynamic/process check-the-key golden-ending released
info/acknowledge golden-ending wind-the-clock released
coin/collect golden-gear with GEAR-1 coin collected
task/solve/secret "CLOCKWORK" story completed, gamesFinished +1, clocksWound +1
POST /v2/session/{id}/end status Finished

Variants that were tested as well:

  • Church path: choose church-photo and upload a photo (task/solve/input, multipart) – same result.
  • Skip path: skip fountain-rivers after 120 s – keysFound stays 2, check-the-key releases ending.
  • Skipping earlier is rejected with 400 session:49.