inform7

how to access the verb the player just typed?


I want to use the verb the player just used in the response.

This is easy with nouns ([the noun]), but in the manual I didn't find something for the verb/action.

This is what I want to do:

Instead of attacking someone:
   say "How do you want to [verb] [the noun]?".

The player could have tried to kill, attack, break, etc. someone and I want to use the exact verb he/she used.

Also: Is there a list of all the standard items one can use in [] while print a response?


Solution

  • The parser doesn't really have a concept of "verbs", it only matches the command to a pattern that has some special tokens (typically the nouns) but verbs are not one of them.

    Also note that the parser discards the original command after it has tokenized it: in other words [the noun] doesn't actually contain the word that the player has used, but the printed name of the noun. So if you have:

    The dragon is an animal. Understand "beast" as the dragon.
    

    and the player types >ATTACK BEAST, then [the noun] would still print "dragon".

    You have a couple of options:

    say "How do you want to [word number 1 in the player's command] [the noun]?";
    

    This is not recommended because it's not guaranteed that the first word is actually the verb. What if the player commanded >GO NORTH THEN KILL DRAGON or >AGAIN ? The game would ask "How do you want to go the dragon?" or "How do you want to again the dragon?"

    Hitting is an action applying to one thing.
    Understand the command "hit" as something new.
    Understand "hit [something]" as hitting.
    
    Instead of hitting:
       say "How do you want to hit [the noun]?"
    

    I wouldn't do this either, because there's a better option...

    Attacking it with is an action applying to two things.
    Understand the commands "attack" and "hit" as something new.
    Understand "attack [something] with [something]" as attacking it with.
    Understand "hit [something] with [something]" as attacking it with.
    [and so on]
    

    Now Inform automatically asks "What do you want to attack/hit/kill the dragon with?" depending on which verb the player used.

    This is also vastly better than the original "instead of" approach, because now the player can just answer the question with one word (">SWORD") – if they did it with the instead rule, the parser wouldn't understand what they meant.