§2.3. Using the Player's Input

We may sometimes want to capture specific words the player has used and then feature that text elsewhere in the game.

Terracottissima Maxima demonstrates using text to describe objects; Mr. Burns' Repast lets the player refer to a fish by any of a number of names, and changes the way the fish is described as a result.

More specialized effects are also possible: Xot shows how to collect the player's erroneous input and store the command line to be printed back later. Igpay Atinlay shows how to parrot the player's command back in pig Latin form.

* See Animals for a dog which the player can re-name

* See Traits Determined By the Player for a way to let the player name the player character


arrow-up.pngStart of Chapter 2: Adaptive Prose
arrow-left.pngBack to §2.2. Varying What Is Read
arrow-right.pngOnward to Chapter 3: Place: §3.1. Room Descriptions

*ExampleIgpay Atinlay
A pig Latin filter for the player's commands.

Suppose we have an unhappily mutated fish that the player can refer to by any of a number of species names, or any word followed by -fish. We want to reject these commands, but preserve a memory of what the player last tried to call the thing:

"Mr. Burns' Repast"

Wharf is a room.

There is an unknown fish in the Wharf. The unknown fish has some a text called the supposed name. The description of the unknown fish is "The victim of heavy mutagens, this thing is not really recognizable as any species you know.".

Fish variety is a kind of value. The fish varieties are salmon, albacore, mackerel.

Rule for printing the name of the unknown fish:
    if the supposed name of the unknown fish is "", say the printed name of the unknown fish;
    otherwise say the supposed name of the unknown fish.

After reading a command:
    if the unknown fish is visible and player's command matches the regular expression "\b\w+fish":
        let N be "[the player's command]";
        replace the regular expression ".*(?=\b\w+fish)" in N with "";
        now N is "[N](?)";
        now the supposed name of the unknown fish is N;
        respond with doubt;
        reject the player's command;
    otherwise if the unknown fish is visible and the player's command includes "[fish variety]":
        now supposed name of the fish is "[fish variety understood](?)";
        respond with doubt;
        reject the player's command.

To respond with doubt:
    say "You're not [italic type]sure[roman type] you're seeing any such thing."

Test me with "get swordfish / look / touch monkfish / look / listen to tunafish / x fish / x salmon / look".

**ExampleMr. Burns' Repast
Letting the player guess types for an unidentifiable fish.

Suppose we have an unhappily mutated fish that the player can refer to by any of a number of species names, or any word followed by -fish. We want to reject these commands, but preserve a memory of what the player last tried to call the thing:

"Mr. Burns' Repast"

Wharf is a room.

There is an unknown fish in the Wharf. The unknown fish has some a text called the supposed name. The description of the unknown fish is "The victim of heavy mutagens, this thing is not really recognizable as any species you know.".

Fish variety is a kind of value. The fish varieties are salmon, albacore, mackerel.

Rule for printing the name of the unknown fish:
    if the supposed name of the unknown fish is "", say the printed name of the unknown fish;
    otherwise say the supposed name of the unknown fish.

After reading a command:
    if the unknown fish is visible and player's command matches the regular expression "\b\w+fish":
        let N be "[the player's command]";
        replace the regular expression ".*(?=\b\w+fish)" in N with "";
        now N is "[N](?)";
        now the supposed name of the unknown fish is N;
        respond with doubt;
        reject the player's command;
    otherwise if the unknown fish is visible and the player's command includes "[fish variety]":
        now supposed name of the fish is "[fish variety understood](?)";
        respond with doubt;
        reject the player's command.

To respond with doubt:
    say "You're not [italic type]sure[roman type] you're seeing any such thing."

Test me with "get swordfish / look / touch monkfish / look / listen to tunafish / x fish / x salmon / look".

***ExampleTerracottissima Maxima
Flowerpots with textual names that might change during play.

***ExampleXot
Storing an invalid command to be repeated as text later in the game.