Chapter 17: Activities
17.33. Printing a parser error

1. When it happens. The parser is the part of the run-time software, included in all works produced by Inform, which tries to match the player's command against the grammar provided by the work. When it is unable to make a valid match, the parser prints an error to the player: for instance,

> BIFURCATE TREE
That's not a verb I recognise.

There are some 19 possible messages, and we can distinguish them using the following conditions:

if the parser error is didn't understand...
if the parser error is only understood as far as...
if the parser error is didn't understand that number...
if the parser error is can't see any such thing...
if the parser error is said too little...
if the parser error is aren't holding that...
if the parser error is can't use multiple objects...
if the parser error is can only use multiple objects...
if the parser error is not sure what it refers to...
if the parser error is excepted something not included...
if the parser error is can only do that to something animate...
if the parser error is not a verb I recognise...
if the parser error is not something you need to refer to...
if the parser error is can't see it at the moment...
if the parser error is didn't understand the way that finished...
if the parser error is not enough of those available...
if the parser error is nothing to do...
if the parser error is I beg your pardon...
if the parser error is noun did not make sense in that context...

2. The default behaviour. Prints the message in question.

3. Examples. (a) Perhaps for newcomers:

After printing a parser error:
    say "If you are new to interactive fiction, you may like to try typing HELP."

(b) Or to give the parser a certain amount of character:

Rule for printing a parser error when parser error is I beg your pardon:
    say "What's that? Speak up, speak up." instead.

Rule for printing a parser error:
    say "That's a rum thing to say, and no mistake." instead.


355
* Example  WXPQ
Creating a more sensible parser error than "that noun did not make sense in this context".

RB

The parser error "That noun did not make sense in this context" arises instead of "You can't see any such thing" when the player uses a command that could apply to any item in the game -- that is, a command such as

Understand "go to [any room]" as going directly to.
Understand "talk about [any subject]" as discussing.

...and so on. The idea here is that "You can't see any such thing" isn't a sensible rejoinder when the player doesn't really need to be able to see the object.

Nonetheless, "That noun did not make sense..." is itself a fairly dry and uninformative response, and we may want to override it to something more appropriate for the specific kind of context in which it might appear. For instance:

"WXPQ"

WXPQ Studio is a room. "After about 2 AM, no one is listening anyway, so you can more or less make up whatever you like to fill the airwaves."

John F Kennedy, Elvis, Ralph Nader, Tony Blair, and single-origin chocolate are things.

Understand "talk about [any thing]" or "discuss [any thing]" as discussing. Discussing is an action applying to one visible thing.

Carry out discussing:
    say "You babble for a while about your [one of]interest in[or]hatred of[or]passionate devotion to[or]conspiracy theory concerning[or]mother's secret love affair with[as decreasingly likely outcomes] [the noun]."

Rule for printing a parser error when parser error is noun did not make sense in that context:
    say "For once, you're at a loss for anything to say."

Test me with "discuss Elvis / discuss Kennedy / discuss chocolate / discuss narratology vs ludology debate".

Note that this solution works as simply as it does because we only have one command in the game that can apply to an "[any]" token. If we had several, we'd need to distinguish between the parser error attached to "discuss" and the parser error attached to "go to" (for instance). In that case, we might instead write something like

Rule for printing a parser error when parser error is noun did not make sense in that context:
if the player's command includes "go":
    say "There's no such place you know how to get to.";
otherwise:
    say "For once, you're at a loss for anything to say."

356
*** Example  Xot
Storing an invalid command to be repeated as text later in the game.

RB


PreviousContentsNext