I7: Having some issues with clothing with pockets

I’m working on making a room where you can’t leave without finding a hidden key in the room. It seems to mostly work except for a problem: The game doesn’t recognize the key at all. I want it to work whether the key is in a pocket or your main inventory and it works in neither. You cannot ever leave. Here’s the code in question:

Clothing is a kind of thing. Clothing is wearable.  
Understand "clothing/clothes/garment/garments" as clothing.   
Pants is a kind of clothing.  
A pocket is a kind of container. The carrying capacity of a pocket is 2. A pocket is a part of every Pants.

A burlap pants is a kind of pants. The description is "These are extremely uncomfortable itchy pants. They have a small pocket sewn on by you that looks like it may fall off at any moment."
The old burlap pants is a burlap pants.

The shack key is a thing. The description is "This is a small iron key for the lock of your shack door. Not that there's anything in there anyone would want."

That creates the pants in question. The following handles the key and the condition that keeps you from leaving:

After taking the shack key for the first time:
	if the player wears the old burlap pants:
		now the shack key is in the pocket;
		say "You pick up the key and put in your pants pocket for safe keeping. Hopefully.";
	else:
		say "You pick up the key. If only you had a pocket to put it in...";

Before going north from Your shack:
	if the player does not carry the Adventurer's Cloak:
		say "You feel like you've forgotten something." instead;
	if the player does not carry the shack key or the shack key is not in the pocket:
		say "You realize you don't have your key. You should probably find that before you leave." instead.

North, of course, is the direction you leave the room.

My assumption is that “if the player does not carry the shack key or the shack key is not in the pocket:” doesn’t work how I think it does. (though the game runs, so it’s apparently valid syntax.) What I’m trying to say is “If the player doesn’t have a key in their inventory or in their pocket, then say”

So, any ideas on how to make this work?

You want “if the player does not carry the shack key and the shack key is not in the pocket”.

This is an old programming gotcha; it would happen in any programming language.

2 Likes

You could also say “unless the player carries the shack key or the shack key is in the pocket”.

The key is that you want “not (player carries key or key is in pocket)”, which is equivalent to “(not player carries key) and (not key is in pocket)”.

1 Like

Considering I know some C, you think I would have spotted that. But I didn’t.

But thank you!

Perhaps it’s worth mentioning that the game world logic might not be doing what you expect.

The phrase

player does not carry the shack key

means that the key is not being directly carried by the player, i.e. in the PC’s “hands” – which I’m guessing you’ve already discovered. Meanwhile the phrase

the shack key is not in the pocket

(a phrase which I’m not sure how it’s even getting past the compiler in your example code) can at best mean that the key is not in the pants pocket – regardless of whether or not the PC is wearing (or even carrying) the pants. Usually the way that code like this compiles means instead that the key is in a pocket, i.e. some pocket in some pair of pants somewhere (even off-stage), and I doubt that’s what you want.

Your use case is common enough that there’s a special relation built in: the enclosure relation. A thing is enclosed whether it is directly or indirectly carried. You might want to change the code

if the player does not carry the shack key or the shack key is not in the pocket:

to

if the player does not enclose the shack key:
4 Likes

Interesting. I just changed the “or” to an “and” and it started working, but enclose seems like it might be a better solution as it would cover more than just pockets. (Which isn’t a situation that exists in the game as written right now, but could in the future.)

Thanks for the answer!