Snippetage by Dave Robinson
Version 2
Some functions for setting and use of snippets (parts of the player's command).
Snippetage has several rules to allow us to make and manipulate snippets more easily. Snippets in Inform 7 are fragments of the player's command that start at a certain word and go on for a certain number of words. This extension gives rules for working out what numbers are the start, end and length for snippets; it tells us if a snippet is valid or invalid, and it defines a couple of other handy things like the "verb word" snippet. Any valid snippet can be used in a say rule, or matched against a topic. So you can put:
say "You used the verb [verb word]."
or
if the word at the end of the player's command matches "bananas"....
or
if the snippet at the verb position of length 2 matches "look in"...
A snippet is decided to be valid if its start is in the player's command and ends later in the player's command. So
if the snippet at word 1 of length 0 is invalid, say "That snippet is invalid."
would indeed say it was invalid (because it has zero length), and
if the snippet at the end of the player's command of length 2 is invalid, say "That snippet is invalid."
would also say the snippet is invalid, because it extends beyond the end of the player's command.
|
Example Pedantic Bob Some simple printing and matching of snippets, and an input-quoting error message |