Doors: Why does Inform try to unlock it with itself?

This is a fairly simple question, but it’s somewhat frustrating to me. By default when someone just types “unlock (door)” the parser tries to pick up the door in order to use it on itself. Which then fails because the door is fixed in place, but still I don’t know why that’s the default action and it comes across a little clunky as a player. I even created a new project with just two rooms and a door connecting them to make sure it wasn’t something weird I’d done.

I just want to know how to just get Inform to ask for a key or give some other failure message rather than nonsensically trying to solve the issue by picking up the door itself.

Let’s say the player has his house key and he’s at the locked front door. If the player just types “unlock door” you can do the following code:

does the player mean unlocking the front door with the house key:
it is very likely.

And Inform will now assume that’s what the player meant.

But I’m talking about a situation where the door is never meant to be locked or unlocked and has no key. It’s just something a person might type that gets a very odd response. Instead of just asking for clarification or noting the door is already unlocked.

I tried to throw in a
Instead of unlocking (the door) with something, say “The door is already unlocked.”

But that doesn’t really work. Probably because it doesn’t even kick in until after the parser is trying to pick up the door.

And also was hoping for something more universal to all doors rather than having to put exceptions for every one.

In the scheme of parsing, I believe that an action requiring two things will always try to find a second noun first (the-supply-a-missing-noun routine has to complete before the Instead rule kicks in to fail it), and the only time you’ll get the nonsensical reflexive-door-unlocking is when the player doesn’t have another object in scope or on their person to try.

Perhaps this might work (not tested):

Rule for supplying a missing noun when unlocking the Front Door:
     say "The door is already unlocked." instead.

Gets this error:

Problem. You wrote ‘Rule for supplying a missing noun when unlocking the gate’ but I don’t understand the ‘when/while’ clause, which should name activities or conditions.

Maybe “Rule for supplying a missing noun when unlocking the gate with something

The actual action is “unlocking it with”, sorry!

Good news is that compiled. The bad news is it still wants to pick up the gate. :weary:

The issue with trying to unlock the door with itself is something that happens when there’s nothing else in the room above a certain priority (not the player, parts of the player, or scenery–not sure what else won’t work) [EDIT: As Hanon just said, ha ha]. If you put a random object in the room where the locked door is, you’ll get the “What do you want to unlock the door with?” message. And if the player is carrying one thing, it will automatically try to have the player unlock the door with that.

I believe zarf has said that he solves this problem by making sure the player always has something in their inventory.

You can eliminate the actual attempt to implicitly take the door like this:

Before implicitly taking a door while unlocking: 
	say "You don't have anything to unlock [the noun] with."
	
For implicitly taking a door while unlocking: stop.

The idea being that you never want to be trying to take a door while unlocking, so this can only happen when the parser has chosen to try unlocking something with a door.

Unfortunately this won’t eliminate the “(first taking the door)” message. That’s hard to get rid of, because it’s pretty deep within the parser. If we were talking about the first noun, you could use the Clarifying the Parser’s Choice activity, but that doesn’t run on second nouns, unfortunately. (The thing after the “with” in “unlocking it with.”)

Hanon is right that you could try supplying a missing noun–in this case it’s supplying a missing second noun. This also requires writing an extra grammar line with a missing noun, like this:

Understand "unlock [door]" as unlocking it with.  [note that this is one noun short--usually you need to say "unlock [something] with [something]"]

For supplying a missing second noun when unlocking: 
	say "You'll have to say what to unlock [the noun] with."

The problem is that this will preempt the mechanism for picking a second noun, or asking which do you mean, even when you want it to run. If you don’t mind having the game choose the second noun automatically, you could include an otherwise clause for when the player carries the matching key of the noun and choose that.

For supplying a missing second noun when unlocking:	
	if the player carries the matching key of the noun:
		say "(with [the matching key of the noun])[command clarification break]";
		now the second noun is the matching key of the noun;
	otherwise:
		say "You'll have to say what to unlock [the noun] with."

If you do mind–like figuring out which key unlocks it is a puzzle–then I don’t know if there’s a way to get the “What do you want to unlock the door with?” back after deciding not to print the “You’ll have to say what to unlock it with” message.

FWIW this is the complete compilable code I have to do my stuff:

yard is a room. front hall is a room.

The front door is a locked door. It is north of yard and south of front hall.

A flower is scenery in the yard.

Before implicitly taking a door while unlocking: 
	say "You don't have anything to unlock [the noun] with."
	
For implicitly taking a door while unlocking: stop.

The driveway is south of yard. A rock and a key are in the driveway. The key unlocks the front door.

Understand "unlock [door]" as unlocking it with. 
		

For supplying a missing second noun when unlocking:	
	if the player carries the matching key of the noun:
		say "(with [the matching key of the noun])[command clarification break]";
		now the second noun is the matching key of the noun;
	otherwise:
		say "You'll have to say what to unlock [the noun] with."

test me with "unlock door/s/take all/n/unlock door".

Another thing is that the extension Locksmith by Emily Short has lots of convenient stuff involving locks and might help, but I don’t know if it does anything about this particular set of problems.

1 Like

That’s a pretty complete rundown, thanks! I definitely see how the different solutions would depend on what you’re trying to do. I think I’m okay just removing picking a second noun for what I’m doing right now. It shouldn’t prove to be much of a bother.

I guess as a real quick bonus, is there an easy shortcut for the door’s open state?

In other words if I wanted to write a description of the door such as:

The gate is north of Room 1 and south of Room 2. The gate is a door.
Instead of examining the gate, say "The gate is currently [??]."

Where the ?? would be something to call the open/closed state of the gate.
(I did it with instead, because I’m not sure doors have attached descriptions like rooms and objects do? But that might be wrong.)

Doors do have a “description” property used when examined.

The description of the gate is "It is currently [if open]open[else]closed[end if]."

This may have downsides that haven’t occurred to me, but here’s what I came up with after reading the original question:

Nounlessly unlocking is an action applying to one touchable thing. Understand "unlock [something]" as nounlessly unlocking.

Report nounlessly unlocking:
	if the noun is locked:
		say "To unlock something, you'll have to say what you want to unlock it with, for example, 'Unlock door with key.'";
	otherwise:
		say "[The noun] [aren't] locked."

Edit: I guess “nounlessly” isn’t accurate since there actually is a noun (there just isn’t a second noun). Oh well. It’s easy enough to give the action a different name.

On a tangential point, if the player is actually supposed to open a locked door without a key, that is, indeed, (lock)picking the door ?

Granted, today burglary IF are somewhat outmoded, but sometimes can have sense in narration.

Best regards from Italy,
dott. Piergiorgio.

In Alias ‘The Magpie’, which uses the Locksmith extension, I had:

Understand "pick [something]" as unlocking keylessly.
Understand "pick [something] with [something]" as unlocking it with.
Understand "lock" as any locked door.

I then made the set of lockpicks the matching key for the door in question.

On the contrary, it’s very much back in vogue.

1 Like