36. A complete, reusable interaction pattern
This example puts the pieces together without hiding a large framework behind them. It reads saved state, checks inventory, prevents a second simultaneous attempt, calls gameplay actions and reports a useful return value.
global archive_open = false
global archive_busy = false
global score = 0function unlock_archive(): boolean
if archive_open or archive_busy
return false
end
if not has_inventory("key")
say "The archive key should fit this lock."
return false
end
archive_busy = true
try
play_sound({"assetId": "chime", "channel": "puzzle"})
archive_open = true
score += 5
show_message({"text": "Unlocked.", "duration": 1.5})
catch problem
warn(problem["message"])
end
archive_busy = false
return archive_open
endfunction run()
return unlock_archive()
endUse archive_open to restore the door’s appearance on room entry. Clear transient busy flags deliberately when loading or restarting a puzzle; saving in the middle of an interaction should not leave it locked forever. If an action fails after the fact is set, decide whether the story should stay completed or roll back. That is a design decision, not something try/catch chooses for you.
The later reference chapters are lookup material. Look up the exact function, property key or event phrase you need, then return to this small interaction pattern. Most adventure logic is still a requirement, a state change and a response.
