| 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.

It has sometimes been suggested that IF should allow for the player to use adverbs, so that doing something "carefully" will have a different effect from doing it "quickly". There are several inherent challenges here: it's a good idea to make very sure the player knows all his adverb options, and the list of possibilities should probably not be too long. Another trick is that adverbs complicate understanding commands, because they can occur anywhere: one might type >GO WEST CAREFULLY or >CAREFULLY GO WEST, and ideally the game should understand both. After reading a command is the best point to do this sort of thing, because we can find adverbs, interpret them, and remove them from the command stream. So: "Cloves" Manner is a kind of value. The manners are insouciantly, sheepishly, and defiantly. Now we have, automatically, a value called manner understood to be used whenever parsing manners, and we can use this even during the "after reading a command" stage, so: After reading a command: if the player's command includes "[manner]" begin; cut the matched text; otherwise; say "But how, my dear boy, how? You simply can't do something without a pose. Thus far you have mastered doing things defiantly, sheepishly, or insouciantly."; reject the player's command; end if. When play begins: change the left hand status line to "Behaving [manner understood]"; change the right hand status line to "[location]"; change the manner understood to insouciantly. The Poseur Club is a room. "Lady Mary is laid out on a sofa, her wrists bandaged importantly[if the manner understood is insouciantly] -- and she looks all the more depressed by your indifference to her state[end if]; Salvatore is at the gaming table, clutching his hair with both hands[if the manner understood is defiantly] -- though he looks up long enough to snarl in response to that expression of yours[end if]; Frackenbush is muttering lines from another of his works in progress, as though poetry has nearly made him mad[if the manner understood is sheepishly]. But he spares you a reassuring smile. He's not a bad fellow, Frackenbush[end if]. The usual people, in short." Instead of doing something other than waiting or looking: say "Dear. No. That would smack of effort." Instead of waiting when the manner understood is sheepishly: say "You scuff your foot against the ground for a moment, and allow a seemly blush to creep over your cheek. It's quite effective, you are sure, though you can't look up and see how it is going." Instead of waiting when the manner understood is insouciantly: say "Thrusting your hands into your pockets, you whistle a jaunty tune. 'Do shut up,' says a Melancholy Poseur from over by the window." Instead of waiting when the manner understood is defiantly: say "You raise your chin and give a pointed glance around the room as though to say that you are waiting for someone; you are unembarrassed about waiting for her; you have by no means been stood up; and the first person to comment will receive a poke in the eye." Before looking when the manner understood is sheepishly: say "You gaze up from under your brows..." Before looking when the manner understood is defiantly: say "You cast a withering gaze over the room." Before looking when the manner understood is insouciantly: if turn count > 1, say "You turn an eye to your surroundings, looking faintly-- just faintly-- amused." Test me with "wait / wait insouciantly / sheepishly look / defiantly look / look insouciantly". The qualification about turn count is to prevent this before message from occurring when the player first looks around the room (automatically) at the start of play. Note that to test this example, one must type INSOUCIANTLY TEST ME, and not simply TEST ME: a poseur's work is never done.

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

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