actions involving more than 2 things?

I’m making a game (my first attempt at IF) in inform 7. In the game the player needs to lockpick a safe, and can optionally lockpick other locks throughout the game.

I really want the lockpicking to require two items (only because I know a little about it and I know you need one thing to apply turning pressure to the lock while another thing is inserted into the lock to set the pins in place).
what I want to do is this:

lockpicking is an action applying to 3 things. understand "pick [something] with [something] and [something]" as lockpicking.

unfortunately it seems that inform doesn’t let me have actions that involve more than 2 nouns. The only work around I have right now is to have the player do a “make lockpick”, which takes away the two items that would be used to pick the lock and gives an item called “lockpick”

is there any way to make an action like this? that involves 3 or more things?
I’ve toyed with the idea of using:

understand "pick safe with [something] and [something]" as lockpicking.

but that will get rather complicated if the player tries to pick other locks (which they should be able to do).

You’re correct that Inform does not support three-thing commands, so, yes, if you want two-tool picking, you’ll have to go with a more “creative” solution. Here are two possibilities:
-If there’s only ever one locked thing in the location, you could indeed say “pick [locked-thing] with [something] and [something],” where [locked-thing] is a token that expands to include all of the names of lockable things in your game, and you decide on which one they mean by assuming they mean the one that is in front of them. Obviously this fails if you have several locks available at any given time.

-Have lockpicking be a separate “mode,” like how some games model conversations. So your player types “pick lock,” which brings up a prompt saying “what is the first tool you want to use?” and then “what is the second tool you want to use?” This has the main drawback of being tedious for the player, especially if several tool combinations will be needed to pick a single lock.

However, that said, isn’t the-part-applying-torque always the same? If I were a player, I’d feel like mimesis was pretty well served if I just typed “pick brass lock with half-diamond pick” (thanks, Wikipedia!), and just have the torsion wrench part assumed.

WARNING! I don’t really know what I’m doing and what problems this code might cause.

It seems to me that if you want “Do X with Y and Z” you might be able to fudge it up by declaring that the second takes multiple objects and then using the multiple-object list, thus:

[code]Jewelry Store is a room. “A jewelry store with a locked door to the north.” The glass case is a transparent locked container in Jewelry Store. It is fixed in place. It contains a ring. The safe is a locked container in Jewelry store. It is fixed in place. It contains a pendant. The glass box is a transparent openable container in Jewelry Store.
The street is a room.
The store door is a door. It is scenery. The store door is north of Jewelry store and south of the street. The store door is locked.

The player carries a thingummy, a hoojab, and a whatsit. The description of the thingummy is “A thingummy. You can use it and the hoojab together to pick a lock.” The description of the hoojab is “A hoojab. You can use it and the thingummy together to pick a lock.” The description of the whatsit is “A whatsit. It… doesn’t really do anything.”

Picking it with is an action applying to one thing and one visible thing. Understand “Pick [something] with [things]” as picking it with. [The second noun is “visible,” meaning that we don’t have to touch it to perform the action, because our “check picking” rule requires us to be able to pick it up anyway. So if one of our lockpicks is visible but not reachable the action will be stopped when we try to pick it up. Making the second noun visible prevents Inform from doing extra accessibility checks; otherwise, if we tried “pick safe with thingummy and hoojab” when the hoojab couldn’t be accessed, we’d get one “failed the basic accessbility rule” message when we tried to take the hoojab while checking picking the safe with the thingummy, and another “failed the basic accessibility rule” while picking the safe with the hoojab.]

Check picking:
if picking-completed is true:
stop the action;
otherwise if the noun is not locked:
say “[The noun] is not locked.”; [this is short a line break, for reasons I don’t understand]
now picking-completed is true;
stop the action;
otherwise: [we try to pick up everything we’re using to pick before doing anything else]
repeat with item running through the multiple object list:
if the player does not hold the item:
say “(first taking [the item])[command clarification break]”;
try taking the item;
if the player does not hold the item:
now picking-completed is true;
stop the action.

Picking-completed is a truth state that varies. Picking-completed is usually false.
After reading a command: now picking-completed is false.

Carry out picking:
if picking-completed is true:
stop the action;
let L be the multiple object list;
unless L is {thingummy, hoojab} or L is {hoojab, thingummy}:
say “You need both the thingummy and hoojab to pick a lock, and nothing else.”;
now picking-completed is true;
stop the action;
otherwise:
say “Using the thingummy and the hoojab, you unlock [the noun].”;
now picking-completed is true;
now the noun is unlocked.

The silently announce items from multiple object lists rule is listed instead of the announce items from multiple object lists rule in the action-processing rules.
This is the silently announce items from multiple object lists rule:
unless picking:
if the current item from the multiple object list is not nothing, say “[current item from the multiple object list]: [run paragraph on]”.

After going north from Jewelry Store:
if the player carries the ring and the player carries the pendant:
say “Success!”;
end the story saying “You’re a great burglar”;
otherwise:
say “You get away without everything you came for.”;
end the story saying “Oh well”.

[/code]

This is obviously very non-robust – it lets you pick anything with the thingummy and the hoojab, and it would take some messing around with lists to allow for other lockpick sets. Also the rule-succeeds/rule-fails business is kind of messed up; if the object is already unlocked, then the rule is deemed to have succeeded. And there’s a missing line break (which, if it’s consistent, could just be added in manually). And you really want to let people pick the lock, instead of the case/door/safe. And probably redirect unlocking to picking where appropriate. But it might be a start.

The example “The Left Hand of Autumn” might be useful here; it’s where I got the “silently announce items etc.” rule, which prevents extraneous “thingummy:” and "hoojab:"s from appearing.

All that said, I think tove is right that it’s enough to let people pick locks with one thing. Note also that I know even less of the art of lockpicking than she does (not that I believe your protestations of ignorance, Ms. Byzantine Perspective).

Also, this method won’t work at all for commands like “Put butter on bread with knife”; it only works because the multiple-object list and [things] token allow us to cram more than one noun into the second-noun slot.

[UPDATED because I forgot to make the door scenery.]
[UPDATED Oct. 2013: The code for implicitly taking the lockpicks was all messed up; changed it.]

Actually, your idea of collecting the two items into a lockpick set is probably a lot better. It would be user-friendly to automate it, so that whenever the player has the thingummy and the hoojab the game automatically takes them away and replaces them with a lockpick set.

Here’s how I might do that – making it so you can never break up the lockpick set, which is much simpler. (And I added a case for where the thing you’re trying to pick doesn’t even have a lock.)

[code]Jewelry Store is a room. “A jewelry store with a locked door to the north.” The glass case is a transparent locked container in Jewelry Store. It is fixed in place. It contains a ring. The safe is a locked container in Jewelry store. It is fixed in place. It contains a pendant.
The street is a room.
The store door is a door. It is scenery. The store door is north of Jewelry store and south of the street. The store door is locked.

A thingummy is in Jewelry Store. A hoojab is in Jewelry store. A lockpick set is a thing.
Every turn:
if the player carries the thingummy and the player carries the hoojab:
say “The thingummy and the hoojab together form an excellent lockpick set! You will never separate them ever again.”;
now the thingummy is off-stage;
now the hoojab is off-stage;
now the player carries the lockpick set.

Understand “thingummy” and “hoojab” as the lockpick set when the lockpick set is not off-stage.

PIcking is an action applying to two things. Understand “Pick [something] with [something]” as picking.

Check picking:
if the noun is not lockable:
say “[The noun] doesn’t even have a lock.”;
stop the action;
otherwise if the noun is not locked:
say “[The noun] is already unlocked.”;
stop the action;
otherwise if the second noun is not the lockpick set:
say “You’ll need a complete lockpick set, consisting of a thingummy and a hoojab.”;
stop the action.

Carry out picking:
say “You pick the lock of [the noun].”;
now the noun is unlocked.

After going north from Jewelry Store:
if the player carries the ring and the player carries the pendant:
say “Success!”;
end the game saying “You’re a great burglar”;
otherwise:
say “You get away without everything you came for.”;
end the game saying “Oh well”.[/code]

If you’re still into actions with more than two nouns you might want to try the following code. It is based on an example in DM4 (the I6 Designer’s Manual):

[code]The third noun is an object that varies. The third noun variable translates into I6 as “third”.

The understand token third something translates into I6 as “THIRD_NOUN_TOKEN”.

[cf. DM4, p. 489]

Include (-
Global third;
-) after “Definitions.i6t”.

Include (-
[ THIRD_NOUN_TOKEN x;
x = ParseToken(ELEMENTARY_TT, NOUN_TOKEN);
if (x == GPR_FAIL or GPR_REPARSE) return x;
third = x; return GPR_PREPOSITION;
];
-).[/code]

Now you can define your 3-noun action like this:

[code]Lockpicking is an action applying to two things.

Understand “pick [something] with [something] and [third something]” as lockpicking.

Report lockpicking: say “You pick [the noun] with [the second noun] and [the third noun].”[/code]

Accordingly, you can add a fourth noun (or even more).

Have you tested this? I tried using this example, but the parser failed to resolve the grammar line, giving only the response “I didn’t understand that sentence”. Here’s the code I used:

[code] The third noun is an object that varies. The third noun variable translates into I6 as “third”.

The understand token third something translates into I6 as "THIRD_NOUN_TOKEN".

[cf. DM4, p. 489]

Include (-
Global third;
-) after "Definitions.i6t".

Include (-
[ THIRD_NOUN_TOKEN  x;
    x  =  ParseToken(ELEMENTARY_TT,  NOUN_TOKEN);
    if  (x  ==  GPR_FAIL  or  GPR_REPARSE)  return  x;
    third  =  x;  return  GPR_PREPOSITION;
];
-).

Lockpicking is an action applying to two things.

Understand “pick [something] with [something] and [third something]” as lockpicking.

Report lockpicking: say “You pick [the noun] with [the second noun] and [the third noun].”

The Paranoia Chamber is a room.

The safe is a thing in the Paranoia Chamber. The player carries a pick and a pliers.

Test me with “pick the safe with the pick and the pliers / pick the safe with the pliers and the pick”.[/code]

Hm, I’m not sure you can do this. Doesn’t having more than three understand tokens total in the grammar line cause the I7 compiler to throw an error?

–Erik

1 Like

Sorry, you’re right, my example is not working here. I’ve tested the DM4 code before – but with different grammar. The “and” is causing problems.

It works, without “and”, though.

Understand "pick [something] with [something] in combination with [third something]" as lockpicking.

I have no idea how to work around the “and”, sorry.

Edit: At least, one could avoid the “and” the dirty way:

[code]After reading a command:
if the player’s command includes “pick”:
if the player’s command includes “and”:
replace the matched text with “plus”;

Lockpicking is an action applying to two things.

Understand “pick [something] with [something] plus [third something]” as lockpicking.

Report lockpicking: say “You pick [the noun] with [the second noun] and [the third noun].”[/code]

It works fine with four nouns:

Understand "pick [something] with [something] plus [third something] plus [fourth something]" as lockpicking.

I think “and” probably invokes the multiple-object list, so you’d have to do it my way (or something like it), or maybe hack up the multiple-object list. If you wanted to allow both forms, maybe you could define one action with an understand statement resembling yours and another (“picking-and” or some such) with an understand statement resembling mine.

Excellent, I’m glad to hear that the compiler doesn’t throw an error. I’m also sad that it throws an error if you try to use four built-in grammar tokens.

–Erik

wow lots of great ideas, thanks all!