Repository navigation
EN Create Custom Code
Français · Type: explanation + how-to · Audience: author · Context: engine repository, created project · Status: ready · Applies from: 4.3.0
When the DSL is not enough, a game defines its own commands in TypeScript. This page explains how they stay compatible with the validator, the solver and the save, and how to write one.
A game exports its own commands from its index.ts (game/index.ts in a created project, games/<id>/index.ts in
the engine repository); a rule or a script then calls one by name:
import type { CustomCommands } from 'quest-n-click/content';
export const commands: CustomCommands = {
sparkle: { pure: true, run: async ({ scene, args }) => { /* draw stars over `scene` for args.ms */ } },
explode: { effects: [{ set: 'chicken_exploded' }, { lose: 'chicken' }, { sfx: 'boom' }], run: ({ scene }) => { /* the blast */ } },
};
// in a rule or a script: { custom: 'sparkle', args: { ms: 1200 } }A custom command has two parts (src/engine/core/custom.ts):
-
effectssays what the command does to the game, as plain commands. They run first, in the browser and in the solver, so a custom command never breaksnpm run solvenor the save. -
runis the visual part, browser only. It gets the game, the state to read, the room, the arguments (args), the presenter (ui), the scene element (scene, DOM painter only) andfast(true while a cutscene is skipped: finish at once). It does not run in node, nor while a cutscene is skipped.
A command that changes nothing says pure: true. The validator refuses a { custom } naming a command the game does
not export, and a command that declares neither effects nor pure; it checks the commands of effects like any
other.
Guarantee ·
custom-effects-everywhere· referenced · scope self-checked by the author (AI), not reviewed A custom command's declaredeffectsapply in the engine and in the solver alike; itsrunruns only when the engine is asked to run it.
Limit ·
run-must-not-change-staterunmust not touch the state. In dev mode (with the journal on) the engine compares the state before and after it, and reports in the journal and the error handler arunthat changed something outside itseffects(custom "x" changed … outside its declared effects). In production nothing stops it, and the solver, the saves and the replay only knoweffects: a change made byrunalone is invisible to them.
- In the game's
index.ts, add the command to the exportedcommands(the template exports an empty one). Put ineffectsevery change to the game, as DSL commands; if there is none, writepure: true.
- Write
run: draw intoscene, wait for your animation, clean up after yourself, and return quickly whenfastis true.
- Call it from a rule, a topic or a script:
{ custom: 'explode', args: { … } }.
-
Check it:
# in the engine repository npm run validate npm run solve# in the created project npx quest-n-click validate npx quest-n-click solveThen play it on the dev server (
npm run dev) with the browser console open: arunthat changes the state is reported there.
A minigame is the other kind of game code: a custom minigame.
The content is data so that every tool can read it (principles). A function cannot be read without running it, and the solver and the validator run in node, without a browser. Declaring the effects as DSL commands lets the solver apply them without the code, lets the save record them, and lets the replay reproduce them; the code keeps what only a browser can do, drawing.
The code is trusted: it ships with the game and is hashed in its fingerprint (trustedExtensions, so a change to a
custom command's code is seen as such). On a hosted Studio, the game's code, custom commands included, runs in a
separate worker that holds no secret of the platform (ADR 0028).
- Callbacks in the content: the solver would have to run the browser's code, or ignore it and prove a different game.
- A plugin that changes the state freely: saves and replays would no longer reproduce a game.
A command whose effect depends on what happens in its run (a reflex game whose outcome changes the story) cannot be
expressed as fixed effects: that is a minigame, whose result the engine records and the solver explores. Some ideas
take a custom command instead of three lines of code.
- ADR 0002, content is data; the code a game needs is trusted and named
- ADR 0003, the solver runs the real engine
- ADR 0028, where a hosted Studio runs the game's code
Generated publication · publication générée — current documentation · documentation courante: quest'n'click 4.4.0 r1, documentation revision · révision de la documentation 8dc717c69acb62c4742b69c54a7e7dfb620f75d8.
Earlier versions and permalinks · versions précédentes et liens permanents: https://wanoo.github.io/quest-n-click/docs/
An edit made in this wiki is overwritten at the next publication · une modification faite dans ce wiki est écrasée à la publication suivante.
Edit the source · Modifier la source · Report an error · Signaler une erreur
Index (6)
Start (6)
Play (9)
Install (17)
- Requirements
- Install from the release archive
- Install from npm, once published
- Install from the repository to work on the engine
- doctor: checking your machine
- Image toolchain
- Audio toolchain: ffmpeg, fluidsynth, Furnace, uv
- Upgrade
- Upgrade notes: 4.4
- Upgrade notes: 4.3
- Upgrade notes: 4.2
- Upgrade notes: 4.1
- Upgrade notes: v3
- Upgrade notes: v2 to v3
- Coming from web-scumm
- Package reference
- Install troubleshooting
Create a game (55)
- Your first game
- Layout of a created project and of the engine repository
- The working loop
- Content principles and the identity contract
- Rooms
- Geometry: placement, walk zones, masks, layers, camera
- Something is visible but unreachable
- Reactions
- Game commands
- Conditions
- Flags, variables and events: which to use
- Custom code
- Characters
- Items and inventory
- World map
- Dialogues
- Scripts and events
- Moving characters: patrols and walks
- Exits
- Chapters and objectives
- State and saves: persistent or temporary, renaming an id, migrations
- Staging: wide rooms and animations
- The stage: lights, particles, floors
- Skin and fonts
- Title and credits
- Heroes: several characters and hero choice
- Built-in minigames
- A custom minigame
- Translations
- Music in stems
- Sound effects
- Voices: per language and per hero
- Images: prompts, cutting sheets, transparency, scale
- Asset provenance
- The storyboard, source of truth
- Puzzle design
- Classic mechanics
- Review pages
- DSL reference
- Checking your game
- What the solver proves
- Solver options
- Playtests
- Remix
- Speedrun for authors
- The sealed ending
- Production template
- Example games
- Working with an AI
- Build and release a game
- Publish on GitHub Pages
- The static game on Clever Cloud
- Other static hosts
- Sub-path, cache and service worker, incomplete deploys, going back
- Testing on a phone over the LAN
Local Studio (24)
- The local Studio: overview and launch
- Edit a room
- Placement and stage
- Preview, apply, undo
- Storyboard
- Assets and cutting
- Check: validator, solver, critical path, heat, health, coverage
- Before and after captures
- Semantic diff
- Play and replay a session
- Rule explainer
- Language and objectives
- Voices and the heroes × languages matrix
- Map
- Notes
- Remix in the Studio
- Music
- The Assistant: bring your own key
- Demo mode and studio-apply
- Local and LAN security
- Studio API
- Local MCP: setting up each client
- MCP tools
- Studio troubleshooting
Team Studio (21)
- What runs where
- Concepts: revision, transaction, span, lease, preview, build
- Starting as an invited dev
- Working together day to day
- Roles and actions: the full matrix
- Invitations
- Managing members
- Write refused on the hosted Studio: stale base revision (409)
- Write refused on the hosted Studio: span locked (423)
- Recovering after a lost lease, a disconnection or a stale preview
- Comments
- Map and semantic diff
- Publishing builds
- Remote MCP
- The game in Git
- Upgrading the engine of a hosted game
- Hosted assets
- The server's command line
- Health and metrics routes
- Trying it locally with compose.yml
- Known limits
Clever Cloud (23)
- Clever Cloud: overview, cost and prerequisites
- Apps and add-ons
- Domains and TLS
- Keycloak
- Generic OIDC and GitLab
- Configuration
- First deployment
- Backups
- RPO and RTO
- Restore the Studio on a fresh installation
- Redeploys
- Upgrading the server and checking state after a migration
- Limits of going back
- Monitoring
- Security
- Rotating keys
- Recovering admin access
- Changing domain or OIDC provider
- Worker, PostgreSQL or Cellar down
- Exporting the game and leaving the installation
- Retention
- Clever Cloud troubleshooting
- Costs and teardown
Reality Bridge and connectors (16)
- The Reality Bridge: what it is
- Quick start
- Guarantees
- Install and run the Bridge
- Backup and restore
- Several tenants
- Signals and the manifest
- The Bridge's command line
- Connectors overview
- Email connector
- Telnet connector
- SSH connector
- Open Badges connector
- The connector SDK
- Security: Biscuit and signatures
- Bridge and connector troubleshooting
Contribute (25)
- Welcome
- Developer setup
- The dev loop
- Before a pull request
- Conventions
- Writing documentation
- Architecture
- Code tour
- Import boundaries
- Which tests run when
- Mutation testing
- The coverage ratchet
- The quality baseline
- CI explained
- Field passes
- Benchmarks
- Releasing
- npm packages
- Decisions and ADRs
- Governance
- Bot pull requests
- Contributing with AI agents
- Security policy
- Code of conduct
- Licences and credits