23. A key, a lock and a one-time reward
This is the basic adventure pattern: reject an already-completed attempt, check the requirement, set the saved fact, then present the result. Set the fact before any long speech or movement so a second click cannot award the same result twice.
global door_open = false
global score = 0function run()
if door_open
say "It is already unlocked."
return
end
if not has_inventory("key")
say "I need the archive key."
return
end
door_open = true
score += 5
play_sound({"assetId": "chime", "channel": "puzzle"})
show_message({"text": "The archive is unlocked.", "duration": 2})
endFigure 6. A script belongs behind the door’s Use response; the object still supplies the hotspot, verb and approach settings.
1. Create the key inventory definition. Import the chime as an audio asset if you want the sound.
2. Create a Boolean variable door_open, initially false, and a numeric score, initially 0.
3. Create a PCA Script with ID unlock_archive and this source. Validate and apply it.
4. On the door’s Use response, add Run Script / Run Visual Script and choose unlock_archive. Test with and without the key.
5. Make room-entry logic restore the open-door appearance from door_open. The saved fact and the displayed model must agree.
