← @electriceeli

Writing readable example games

Organize a game around the changes someone will come here to make. A writer changing a line of dialogue should be able to open the story file. A developer changing when a clue is awarded should be able to find the rule without reading how buttons are drawn.

Module boundaries

File length

Around 200 lines, review the file’s responsibilities. This is a prompt for a human review, not a build limit. Split a shorter file if it mixes unrelated jobs. Keep a longer conversation together if splitting it would make the story harder to follow.

Before extracting a module, name a real edit that would become easier to make. Then trace one player action across the proposed files. If following it requires several files that only forward the same arguments, keep those pieces together.

When the game grows

A one-room game can keep its screens together. As distinct parts of play grow, organize code around the names players and developers use, such as the market, farm, or road encounters. A good time to give a feature a directory is when an ordinary change to it repeatedly sends you through files full of unrelated features.

Statements and names

Use the words a developer will look for: suspect, clueId, and remainingSeconds. Write each state change as a separate statement so its timing is visible. Use a block when a condition controls several actions.

Prefer named functions for actions and screens. Use short arrow callbacks for a single, local calculation. A two-way choice such as picking an image can use a ternary. Give each outcome of a longer decision its own branch. Use comments for reasons a reader cannot infer, such as why the destination must be saved before a fade.

Keep story text, choices, and their conditions together as data. Use two spaces for indentation, double quotes, semicolons, and trailing commas in multiline literals. Wrap code around 100 columns where that helps reading. A line of dialogue can stay intact for editing.

Building a screen

Use small named helpers for repeated browser work. Keep the label and the player’s action visible at the call site. Use a loop when building controls involves attaching behavior or appending elements. Use a short .map() when each input simply becomes one output.

From the accusation screen (scenes.js):

for (const suspect of SUSPECTS) {
  choices.append(createButton(suspect.label, () => actions.accuse(suspect.id)));
}

Where to make an edit in The Quiet Parlour

To change… Start here
How play starts or how the countdown appears Game entry (game.js)
What happens when a player takes a clue or the train leaves Actions (actions.js)
What a player sees, clicks, or focuses Scenes (scenes.js)
What survives a reload or how a saved field is checked Saved game (saved-game.js)
What a suspect says or which accusation solves the case Story (story.js)
How a button or text element is created Elements (elements.js)
How an artist compares a mantel variation with its approved image Sprite preview (sprites.js)

Writing hosted docs