| Chapter 17: Activities |

| 17.25. Reading a command

1. When it happens. When reading a command from the keyboard.

2. The default behaviour. Print the prompt text; wait for the player to type something and press return. Reject an entirely blank line, and treat a command beginning "oops" is considered a correction to the previous one. This is a fairly complicated business, so it is probably best not to change the "for" rules for this activity: "before", and especially "after", are another matter.

3. Examples. (a) To lead absolute beginners in gently:

> Before reading a command while the turn count is 1, say "(This is your chance to say what the protagonist should do next. After the '>', try typing 'take inventory'.)"

(b) The following responds politely but firmly if the player tries to type "please look", say, instead of just "look":

> After reading a command:
> if the player's command includes "please" begin;
> say "Please do not say please.";
> reject the player's command;
> end if.

To explain. Fragments of what the player has typed are called snippets: "the player's command" is the entire thing. We can test if a snippet matches a given pattern like so:

> if the player's command matches "room [number]", ...

This requires an exact match: the weaker condition "includes" only means that the pattern occurs somewhere in the given snippet, so that

> if the player's command includes "please", ...

matches "please look" or "look please", etc. Lastly, the phrase

> reject the player's command

tells Inform not to bother analysing the text further, but to go back to the keyboard. (No time passes; no turn elapses; nothing happens in the simulated world.)

(c) An improved version takes commands like "please drop the coin" and strips "please" from them, but then allows them to proceed normally:

> After reading a command:
> if the player's command includes "please" begin;
> say "(Quelle politesse! But no need to say please.)";
> cut the matched text;
> end if.

"Matched text" is a snippet containing the words which matched against the pattern in the most recent "includes" condition, so in this case it contains just the single word "please". Two phrases allow snippets to be altered:

> replace (... snippet ...) with (... text ...)
> cut (...snippet ...)

Note that "replace" and "cut" can only be used in "after reading a command" rules: not when an action has been chosen and has gone ahead into its rulebooks. Once the reading a command activity has finished, the command is final.

(d) To make the word "grab" an abbreviation for "take all":

> After reading a command:
> if the player's command matches "grab", replace the player's command with "take all".

("Snippet" is actually a kind of value, so we could say "Ah, you typed '[the player's command]'!" or some such if we liked. But in practice only three snippets are likely to be useful: the two mentioned above, "player's command" and "matched text", and the "topic understood", used when matching the "[text]" token in command grammar.)

274
| Example Fore Understand "fore", "aft", "port", and "starboard", but only when the player is on a vessel.

275
| Example Cloves Accepting adverbs anywhere in a command, registering what the player typed but then cutting them out before interpreting the command.

276
| Example Fragment of a Greek Tragedy Responding to the player's input based on keywords only, and overriding the original parser entirely.

> Apologies to the shade of A. E. Housman. "Fragment of a Greek Tragedy" Understand "restart/restore/save/quit" as "[meta-command]". After reading a command: if the player's command matches "[meta-command]", make no decision; say line break; repeat through Table of Current Topics begin; if the player's command includes topic entry begin; say "CHORUS: [reply entry][paragraph break]"; follow the advance time rule; rule succeeds; end if; end repeat; say "[italic type] Pause.[roman type][line break]"; follow the advance time rule; rule succeeds. Table of Current Topics
> topic | reply
> "journey/trip/travel/came/arrived" | "Sailing on horseback, or with feet for oars?"
> "horseback/legs/feet/oars" | "Beneath a shining or a rainy Zeus?"
> "shining/rainy/weather/zeus" | "Mud's sister, not herself, adorns thy boots."
This would be a bit bare if we didn't provide the player with some sort of context at the outset, so let's put some remarks before the first command prompt: Before reading a command while the turn count is 1: say "CHORUS: O suitably-attired-in-leather-boots Head of a traveller, wherefore seeking whom Whence by what way how purposed art thou come To this well-nightingaled vicinity? My object in inquiring is to know. But if you happen to be deaf and dumb And do not understand a word I say, Then wave your hand, to signify as much." This "turn count" condition is why it was useful to follow the advance time rule in "after reading a command": the game (or drama, if you like) will continue to count moves elapsed even though the rest of Inform's command parsing and world model is being ignored. In a longer and more ambitious implementation of this idea, we might want to keep following the turn sequence rules and allow scenes to govern the behavior and responses of the Chorus. And then to give the whole exchange a play's format: The Stage is a room. The room description heading rule is not listed in the carry out looking rules. When play begins: change the command prompt to "YOU: "; change left hand status line to "Fragment of a Greek Tragedy"; change right hand status line to "A. E. Housman". (Because this example manipulates commands outside of the normal parser, the mechanism for TEST will not work here. Try typing commands such as: TELL CHORUS ABOUT JOURNEY / TELL CHORUS ABOUT FEET / TELL CHORUS ABOUT SHROPSHIRE / TELL CHORUS ABOUT ZEUS)

277
| Example Complimentary Peanuts A character who responds to keywords in the player's instructions and remarks, even if there are other words included.

Previous | Contents | Next