Choose how the game should recover
ERROR HANDLING
A player typing the wrong word is a normal part of an adventure. A missing destination room is an authoring mistake. Players should get a sensible response in either case, but your code should handle them differently.
| Expected input | An empty name, a wrong answer or too few tickets calls for an ordinary condition. Explain what the player can do next. Leave the puzzle in a playable state. |
|---|---|
| An optional resource | If a hint preference is missing, start with a documented default. If a voice clip is optional, keep the subtitle available. Record the missing ID if it is something the author needs to fix. |
| An impossible internal value | A ticket balance of −1 violates the rules. Use an assertion while diagnosing where the bad value came from. Before changing inventory or opening the gate, stop that action and log the record and value. |
| An operation that can fail | If a save or write reports failure, preserve the player’s current state. Show a retry or a return path. Display “Saved” only after the operation reports success. |
Read the answer a helper actually returns#
An empty string can be a valid player answer. Zero can be a valid fare. FALSE can be a perfectly good preference value. When failure and success can both look like zero or false, return a separate status such as {"ok": false, "value": 0}. Let the caller decide what to show.
Validate the prerequisites before charging the player. If an action can run twice, check the completion flag on entry, and decide how to restore input on both success and failure.
