Skip to reading
PCA Script Programming

23. A key, a lock and a one-time reward

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView illustrations

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.

Code example
global door_open = false
global score = 0
Code example
function 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})
end

Figure 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.

Page 30 of 357Permalink
Go to page