35. Build one dependable puzzle operation
A finished interaction should have a clear entrance, a condition, a state change, feedback and an exit. Use this checklist to turn the simple key-and-door lesson into a reliable game sequence.
| Operation | Recommended order |
|---|---|
| Take key | Check key_taken. If false, set it true, give the item, update score, hide/disable the pickup, then present feedback. |
| Use lever | Check or set powered explicitly. Update any dependent description/effect. Play feedback. Do not toggle accidentally on repeated calls. |
| Use door without key | Give a useful locked response. Leave the room and inventory unchanged. |
| Use door with key | Apply any permanent unlock flag. Consume the key only if intended. Change to the destination spawn. |
| Return to room | Read saved flags and restore the matching presentation. Do not reset puzzle facts. |
| Load save | Use restored state. Refresh custom presentation through the successful-load path if needed. |
When the player can reach the same operation by mouse, parser, controller or GUI, share the operation. The input routes can be different; the actual rule that decides whether the door opens should be the same.
If a reward depends on several actions succeeding, write that dependency explicitly in a script. The ordinary list runner does not inspect an action's returned error and automatically roll the earlier changes back.
