Which chapter element would you like to add?
Code Locks
Code locks
Code locks let an author hide part of a chapter behind an exact answer. Readers see a prompt, an answer field, and an Unlock button. A lock can be a self-contained story puzzle, or it can save one Game State value when the correct answer is entered.
Preview
Enter 1234 to unlock the safe:
{lock "Enter the four-digit code" answer "1234"}
The safe clicks open. A map rests inside.
{endlock}
This is a plain lock, so it works without starting a game and does not change Game State.
Copyable syntax
Put the prompt and answer in matching straight quotation marks. Place the passage between the opening tag and {endlock}:
{lock "Enter the four-digit code" answer "1234"}
The safe clicks open. A map rests inside.
{endlock}
The reader initially sees Enter the four-digit code, a text field, and Unlock. Entering 1234 changes the control to Unlocked and reveals the passage. An incorrect answer leaves the passage hidden and shows Try again.
Match the answer exactly
Answers are case-sensitive and include every space inside the quotation marks. For example, Ember, ember, and Ember are different answers. Tell readers enough to understand the expected form when capitalization or punctuation matters.
Both the prompt and answer must contain text. Use matching straight single or double quotation marks, and do not put another chapter tag inside either value:
{lock 'Speak the password' answer 'Open, sesame!'}
The stone door moves aside.
{endlock}
A code lock is a story puzzle, not secure protection. Do not place private information, real credentials, prizes, or anything else that must remain secret behind it.
Save a Game State value
Add one set game:... assignment when solving the lock should affect later text or choices. First create the target as described in Reader and Game Variables, then use the exact name and capitalization shown on the story's Story variables page:
{lock "Enter the vault code" answer "1234" set game:vault_open = true}
The safe clicks open. A map rests inside.
{endlock}
This form needs an active game. Before the reader starts one, its field is unavailable and the button shows Start game. With a game active, the correct answer sets vault_open to Yes, refreshes visible Game State and inventory, and can immediately change conditional text or continuation choices.
In a compact example, the same pattern may be written as {lock "Enter code" answer "1234" set game:vault_open = true}...{endlock}. Replace ... with the passage shown after the correct answer.
A state-changing lock uses = to set one existing value. It cannot use += or -=, and it cannot change several values. Match the value to the variable type:
- Yes/No accepts
true,false,yes,no,1, or0. - Number, Percent, and Age use a whole number within that type's range.
- Text and Dropdown values may be quoted, and values containing spaces must be quoted.
- A Dropdown value should be one of the choices configured for that variable.
For example:
{lock "Name the marked route" answer "North road" set game:route = "north road"}
The compass needle settles.
{endlock}
Completion, Back, and reset
A plain lock stays open only on the currently loaded page. Reloading the chapter closes it and asks for the answer again.
A state-changing lock saves its completion as a game step. If the lock is still in a visible passage, returning to the chapter during that game restores it as unlocked. Going Back past the completion restores the earlier value and makes the lock available again. Reset Game or Start Over also begins a fresh game in which it can be solved again.
Conditional text can hide an entire lock before or after completion. A hidden lock cannot be answered. If a lock's own saved change hides its surrounding passage, that completion remains saved; making the passage visible again restores the unlocked lock unless the reader has gone Back past its completion.
The saved change occurs only after the correct answer. Wrong attempts do not create game steps or change the target value.
Content and combinations
The hidden passage can contain paragraphs, headings, lists, links, and other supported Markdown. It can also contain supported chapter elements such as a reveal, ordering puzzle, or action button. If an action or ordering puzzle is inside a lock, readers must unlock the surrounding passage before they can use it.
Do not place a code lock inside another code lock. Keep {lock ...} and {endlock} paired, and use a separate block for each answer. To show lock tags as literal text in a chapter, put them in backticks or a fenced block.
The story's Element Theme controls the lock panel, field, button, error state, and unlocked passage without changing the answer or Game State behavior.
Before publishing
Save a draft and test that:
- the prompt tells readers what kind of answer to enter;
- the exact intended answer opens the passage;
- a near match with different capitalization, spacing, or punctuation is rejected;
- the unlocked passage and any elements inside it work on narrow and wide screens;
- a state-changing lock shows Start game before a game begins and saves the intended value afterward;
- conditional text, inventory, and continuation choices refresh after the saved change;
- going Back past a state-changing completion restores the earlier value and makes the lock usable again;
- the lock remains readable with the story's Element Theme in White, Black, and Sepia appearance.
You've reached the end of this Guide topic.
- No further chapters
0 comments
No comments yet
The story has no discussion yet. Leave a note here when a branch gives you something to say.
No chapter comments yet
No one has commented on this branch yet. Add the first note above.