17.33. Printing a parser error

| 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. The one which the parser wants to say is stored in the variable "latest parser error", which has the convenient kind "command parser error". This has the following possible values:

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

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 the latest parser error is the I beg your pardon error:
> 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.

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

367
| Example Xot Storing an invalid command to be repeated as text later in the game. |
RB

In Hitchhiker's Guide to the Galaxy, any erroneous command the player types can return to haunt him later in the game. We could do the same, if we liked, by storing the player's command whenever we print a parser error. This requires us to borrow the idea of "indexed text" -- a more flexible kind of text than the usual "text that varies" -- from the Advanced Text chapter: "Xot" Humiliation Chamber is a room. "A grim, grey-walled room. Cameras watch you from every angle; convex mirrors reflect your actions; and up near the ceiling, where you can't disable it, is a loudspeaker." Last error is indexed text that varies. The last error is "xot". Before printing a parser error: now the last error is the player's command. Every turn when a random chance of 1 in 2 succeeds: say "Over the loudspeaker comes some distorted nonsense. If you listen carefully, it sounds as though some fool is saying '[last error], [last error], [last error]!'" Test me with "wiggle / z / z / z / z / z / z".

Previous | Contents | Next