Understand your note about “with [something]” as opposed to “with [hammer]” bad example perhaps.
A better example would be “light/set [something] on fire” and “burn [something]” and “set fire to [something]” with the possible “with lighter” preposition, perhaps.
(The game is one-room, so only has one possible thing to burn something with. A longer game might warrant a seperate “burning with” action just for multiple sources of fire.)
Anyway, I tried “Understand the command ‘burn’ as burning” but I got an error on complile. I’m not in front of my inform right now, but it was something along the lines of understand not being able to be used in this fasion.
It let me put
UNDERSTAND THE COMMAND “hit” as something new.
UNDERSTAND THE COMMAND “hit” as smashing.
Smashing is an action applying to one thing.
Understand "Smash [something] [text]" as smashing
This would allow for:
or similarly with burn
Is there a downside to coding this way? It seems like otherwise we have to make a ridiculous amount of possible inputs for the same action, and possibly seperate actions (burning, burning it with) all with seperate synonyms for something that only MIGHT come up.
That’s because you’re not using quite the right grammar.
Understand the command “break” as “attack”.
says that the word “break” is being assigned to have the same meanings as the word “attack”. This is how we establish synonyms, and it will mean that “break” and “attack” are interchangeable to Inform. If you have ten different actions that all start with “attack” – say “attack man with gun” is shooting, “attack man with axe” is hacking, “attack man with sword” is slashing, and so on – then for every one of those cases, “break” would be usable in the same place. So you’d immediately get “break man with axe” also to mean hacking, “break man with sword” also to mean slashing, and “break man with gun” also to mean shooting. (Never mind that that is not something that would occur to most English speakers to type; the example is valid from a code perspective.)
This thing of setting up synonyms is a different operation from
Understand “break [something]” as attacking.
…which is instead setting up an action. (Notice “Understand” for actions vs “Understand the command” for synonyms.)
If you set up the action, then “break man” means attacking him, but “break man with gun” will be unrecognized even though “attack man with gun” is still understood.
Yes: the parser will give less accurate feedback to the player about what it’s looking for as a correct command, and the player will get nonsensical responses to input like SMASH BOX ON LISA’S HEAD, in which poor Lisa will be reported as completely unphased by the experience.
As a rule, it’s considered a bad idea to have the parser pretend to understand things it doesn’t, because it muddies the water for the player about what is possible to communicate to this game and what isn’t.
There’s a fairly extensive discussion of the design of commands – in particular, ones that might take multiple inputs or might handle them in different ways – in the Recipe Book here: inform7.com/learn/man/Rdoc29.html and the following page.
If you do want to be able to accept a wide variety of nonsense add-ons to sentences, have a look at Smarter Parser by Aaron Reed. It’s designed to notice when the player’s typed something that is too much information, tell the player what it’s discarding from the command, then retry the command in this revised form. Makes a huge difference to helping the player understand what he’s doing.
This is definitely a trap, particularly if the player uses “with”–in your burning example, it would allow BURN DIARY WITH LIGHTER, but it would consider BURN DIARY WITH WATERMELON to be equally valid.
As I recall, there’s a way to omit the second noun of a two-noun phrase and allow the parser to assume what it is–particularly useful when there’s only one possible second noun–so that the default could be
Understand "Burn [something] with [something] as burning"
But it would also accept
With the second noun assumed to be the lighter. I don’t remember the syntax of how to do this, though.
And BURN DIARY WITH FELONIOUS WATERMELON AND WANTON ABANDON NOT THINKING OF THE CONSEQUENCES AND LOVING EVERY MINUTE OF IT would also be accepted. But while it’s a trap, it’s a potentially very useful one, when used properly. [Moving off topic:]That’s because you can recursively continue to parse the text part of the token, meaning that, with a little work, you can get around Inform’s limitations on how many nouns (two) and values (just one) can be included in a given line of input. I believe there are some discussions on here and maybe on rec.arts.int-fiction that touch on this little technique if anyone’s interested.
I definately see the issues with including “[text]” as part of the parser (such as lighting the diary with the watermelon).
I guess, where’s the limit? Certainly the player can’t expect the parser to behave like a person, so what’s MORE bothersome: having the parser not understand a simple command (Set diary on fire with lighter), or having it simplify a complicated command (set diary on fire with lighter so bobby can see how cool I am, but not so Timmy can see if I can avoid it).
While this is confusing, I suppose it’s better than
I think the latter is better because it is far less likely to result in you accidentally doing something you didn’t want to do. For example, if you said BURN TIMMY WITH WITTY RETORT, you wouldn’t want the parser to actually light him on fire. (Or perhaps LIGHT DRAPES UP WITH FLASHLIGHT might be a better example–you’re trying to illuminate them, not burn them.)
Other folks have already answered why leapfrogging the parser is a bad idea in general, and why this in particular is a bad way to do it.
It’s also important to note that the two examples you’ve opposed don’t accurately depict the tradeoff. Inform can already understand both “set dairy on fire with lighter” and “set dairy on fire” (supplying a second noun) perfectly well, without “that’s not a verb I recognize” errors or parser hacks. Here’s example code:
The Kitchen is a room.
The match is a lit thing in the Kitchen. The bundle is in the Kitchen.
Flaming it with is an action applying to two things. Understand “set [something] on fire with [something preferably held]” or “set [something] on fire” as flaming it with.
Rule for supplying a missing second noun while flaming:
if the player can see a lit thing:
now the second noun is a random lit thing that can be seen by the player;
otherwise if the player is carrying something:
now the second noun is a random thing carried by the player;
otherwise if the player can see something:
now the second noun is a random thing that can be seen by the player;
say “(with [the second noun])”.
Check flaming something with:
if the second noun is not lit:
say “[The second noun] can’t be used to set anything on fire.”;
if the noun is the second noun:
say “You can’t set something on fire with itself!”;
Carry out flaming something with:
say “[The noun] goes up in flames and is soon consumed.”;
remove the noun from play.[/code]
Unfortunately, this seems to be a bug (or at least a design oversight). It ought to work, obviously, but Inform doesn’t seem to consider that the noun might be supplied separately; instead it throws the message:
I suspect that the order of declaration in the original grammar line is significant somehow. The hack that Ron mentioned is probably the best way to do this.
Katz’s second failed example would make a nice shortcut for this (as does Ron’s hackier example), but the canonical way to do it is with a “rule for supplying a missing noun while using”, as in the example I posted:
[code]Understand “exercise” as using [or whatever the full name of the action is].
Rule for supplying a missing noun while using:
if the player can see the exercise machine:
now the noun is the exercise machine;
say “(using the exercise machine)”;[/code]
First, if there is anything else usable in the room with the exercise machine, that’s a problem.
Second, whenever the exercise machine isn’t present, it will respond to “exercise” by trying to use something else and either deliver an odd response or actually use the wrong object (presumably that won’t be the only clarification I want to write for the “use” verb).
Of course I can use “Understand ‘exercise’ as a mistake”, but one tries not to do that when the player’s meaning is perfectly clear.
So is there a way around the “consult” problem? This is actually a serious problem, because of all the ways I would try to look something up in a book, “consult X about Y” (or any syntax that actually involves the name of the book) would be very far down indeed.
Ron: Figured that out myself about 1.5 seconds after posting that, hence why I deleted it. Curse RSS feeds!
I was really just showing you how to use the syntax, since I assumed that was why you replied to my post. I wasn’t trying to demonstrate the optimal implementation of exercise as a special case of a use action . The effect you’re looking for is best handled by a second “exercise” command that maps to using the exercise machine when the player is near it, and prints a default message when the player isn’t. (You could also do that with two “understand as a mistake” lines, or one that contains a conditional.)
Ron and I both mentioned that the “understand as a mistake” hack would work. A second action that remaps to consulting would also work.