I have a box in my game with a pickable lock. (I found some great lockpicking code in the forums that’s working really well for me!) The box has different descriptions based on whether or not it’s closed and locked, closed and unlocked, open and full or open and empty.
The box is a container on the desk. It is fixed in place, lockable and locked. The paperclip unlocks the box. The description of the box is “[if the player is John]You’d put the stuff in the box in a drawer if you had a desk.[end if][if the box is locked and the player is Mary]It’s locked. You don’t see a key for the lock, but a box of this size can’t have a terribly complicated mechanism. [end if][if unlocked-closed is true]The unlocked box sits atop the desk on little lion feet.[end if][if unlocked-open is true]The open box is filled to the brim with paper of various ages, yellowed at the bottom of the stack and seemingly brand-new at the top.[end if][if unlocked-empty is true]The box sits open and empty on the desktop, its satin interior shining dully.[end if]”
As you can see, I’ve been trying to make this work with truth states, because saying [if the box is unlocked]
and [if the box is open]
will start stacking box descriptions once the box is unlocked and open. Here’s the whole business:
Instead of opening the box:
if the player is John, say "You don't need to open the box - you know what's inside." instead;
if the player is Mary and the box is locked, say "John locked it. You might be able to pick the lock with something, though." instead;
if the player is Mary and the box is unlocked, say "You gently open the gilt box.";
now the box is open.
Understand "pick [something] with [something]" as unlocking it with.
Understand "lock" as the box.
Understand "piece of wire" or "wire" as the paperclip.
Report unlocking the box with the paperclip:
say "You unbend the paperclip and stick the end inside the lock. After jiggling the wire around for a few seconds, you feel something pop inside the lock.";
rule succeeds.
Before unlocking something (called TheTarget) with something (called TheObject):
if TheObject is not the paperclip:
Say "That's clearly not going to work." instead;
if TheTarget is not the box:
Say "You're talking nonsense now." instead.
Check locking the box with something:
say "You fail to lock it. You must have broken something inside the lock." instead.
Check unlocking it with:
if the player is John and John is in the office, say "You don't need to open the box - you know what's inside.";
if the player is Mary and Mary does not have the paperclip, say "You'd give it a try, if only you had something suitable for picking locks."
Unlocked-closed is a truth state that varies. Unlocked-closed is false.
After unlocking:
say "You unbend the paperclip and stick the end inside the lock. After jiggling the wire around for a few seconds, you feel something pop inside the lock.";
now unlocked-closed is true.
Unlocked-open is a truth state that varies. Unlocked-open is false.
After opening the box:
now unlocked-closed is false;
now unlocked-open is true.
Unlocked-empty is a truth state that varies. Unlocked-empty is false.
After taking the papers:
now unlocked-open is false;
now unlocked-empty is true.
The papers are in the box. The description of the papers is "It looks like...letters John wrote but never sent? You’ve never known John to be much of a writer."
All that is giving me this output (assuming the player is Mary here and there’s also a paperclip on the desk; obviously there’s other code around this):
>look box
It's locked. You don't see a key for the lock, but a box of this size can't have a terribly complicated mechanism.
>open box
John locked it. You might be able to pick the lock with something, though.
>take paperclip
Taken.
>pick lock with paperclip
You unbend the paperclip and stick the end inside the lock. After jiggling the wire around for a few seconds, you feel something pop inside the lock.
>look box
The unlocked box sits atop the desk on little lion feet.
>open box
You gently open the gilt box.
>look box
The unlocked box sits atop the desk on little lion feet.
In the box is a papers.
>take papers
>i
You are carrying:
a papers
a paperclip
So you see that things are breaking down toward the end there. The second instance of “The unlocked box sits atop the desk on little lion feet.” actually should be “The open box is filled to the brim with paper of various ages, yellowed at the bottom of the stack and seemingly brand-new at the top.” And I didn’t get the default “Taken” message after take papers
, but they’re in Mary’s inventory.
Am I going down a totally wrong road with the truth states thing? Any advice you have about what’s missing or could be improved in this code would be much appreciated. Thanks!