Truth states and object descriptions

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!

1 Like

I wouldn’t recommend that method because manually managing the variables is going to get unwieldy very quickly.

You can pull the description logic to a separate say phrase where you can write it much more cleanly, without any of the restrictions of embedding it all inside the description text.

``````The description of the box is "[box-description][run paragraph on]".

To say box-description:
if the player is John:
say "You’d put the stuff in the box in a drawer if you had a desk.";
if the player is Mary:
if the box is locked:
say "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.";
otherwise if the box is closed:
say "The unlocked box sits atop the desk on little lion feet.";
otherwise if something is in the box:
say "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.";
otherwise:
say "The box sits open and empty on the desktop, its satin interior shining dully."
``````

If the logic is so complex that even the say phrase becomes too messy, the next step would be to make a new rulebook with separate rules for each description, but that’s probably too heavy duty for this case.

4 Likes

Juhana’s advice is excellent. Just a note on this:

This is because of the After rules that you’re using to set various states. After rules by default stop processing the action before you get to the Report rules. If you have something that changes the game state but doesn’t print anything, you can often do that with a Carry Out rule; if that doesn’t work for timing reasons or something, you can put “continue the action” in your After rule. (but with Juhana’s advice you should be able to avoid this completely!)

Sorry, I was out of town and away from my laptop!

Juhana, your code works perfectly, of course. Thank you for your help. And thank you for the extra knowledge, matt w. I know that’s going to come in handy in the course of making this whole thing.

I started this game in Quest, and when it let me down, I started working in Inform. I’m just starting to recognize the ways Inform acts like “regular” code that I’m used to from work and from the old version of the game. Every little bit of advice like this helps, so thanks again!

1 Like