Using a screwdriver to 'unlock' containers


I’m fairly new to IF, so I expect the answer to be a glaringly obvious one that I’ll kick myself for not working out.

I am trying to use:

Understand "unscrew [a locked container]" as unlocking.

But not only does IF not like the verb ‘unlocking’, it also performs the action ‘turning’ when unscrew is used.

I’m still a newb and trawling through the documentation, so I apologise if this is a stupid question! I would appreciate any suggestions you might have.

Thanks in advance.

Hi J’xargo!

The first problem is that the verb “unscrew” is already defined, mapping to the “turning” action. If you want to redefine it, you need to remove the existing grammar line first:

Understand the command "unscrew" as something new.

The second problem is that the “unlocking” action takes two nouns: the thing being unlocked, and the thing being used to unlock it. Some extensions (such as Locksmith) define a new “keyless unlocking” action, which takes only one noun, but you could also do this:

Understand "unscrew [something]" as unlocking it with. Rule for supplying a missing second noun when unlocking it with when the player's command matches "unscrew": now the second noun is the screwdriver.

Probably the easier way to do it would be this.

The Laboratory is a room. There is a screwdriver in the Laboratory.

The player carries an intricate puzzle box. The puzzle box is a locked container. The description of the puzzle box is "Hopelessly complicated. You have no idea how to manipulate all the little buttons to get it open. On the bottom are some screws." Understand "screw" or "screws" as the puzzle box.

The screwdriver unlocks the intricate puzzle box.

Instead of turning the intricate puzzle box when the player is carrying the screwdriver:
    try unlocking the puzzle box with the screwdriver.

This effectively makes the screwdriver into the “key” for the box, thus handling commands like “open box with screwdriver”. The “Instead of turning…” rule means that “unscrew box” will redirect to “open box with screwdriver” when the player has the screwdriver.

Fantastic! Thank you for your swift response. That worked really well for ‘unscrew the intricate puzzle box’.

However, if I wanted to ‘unscrew the intricate puzzle box with the screwdriver’, the screwdriver part is not understood. Let me know if you have any thoughts.

The easiest way would be to add a new grammar line:

Understand "unscrew [something] with [something preferably carried]" as unlocking it with.

That’s a neat piece of code Draconis, I’ve never seen “something preferably carried” before, might need to read up on that :slight_smile:

Excellent, that has worked perfectly. Although, for some reason, I had to remove the word ‘preferably’ to get rid of the error message. Weird.

Thank you so much for your help! No doubt I may be needing it again in the future.

Ah, I messed up the syntax slightly: it’s “something preferably held”, not “carried”. This indicates that it should first try to match something in the player’s inventory, then (if that fails) something in the environs.

Hey guys, I just noticed this and I’m wondering if there is a way to make a more general “Use something on something else” command? I can’t seem to find anything about it in the documentation.

Creating the command isn’t hard. Implementing it can be, depending how general you want to get. And there are various reasons authors and players might not want there to be a general “use” verb. But you could do it like this:

Using is an action applying to one thing. Understand "use [something]" as using. Carry out using a [kind of thing]: try [more specific action]. Carry out using a [different kind of thing]: try [different specific action]. etc...

The more common solution is not to make a “using” action at all, but rather to redirect “use” commands at the parser level. This method has various advantages over the other, but doesn’t allow you to write a rule for “instead of using the soap” or whatever.

Understand "use [an open door]" as entering. Understand "use [a closed door]" as opening. Understand "use [a switched off device]" as switching on. etc...