I’m thinking about entering the Text Adventure Literacy Jam, but it has this crazy rule that input must be restricted to two words. You can’t even enter articles or adjectives. So, my question is, what’s the simplest way to restrict Inform 6 to two-word input?
I know that I can change all the grammar and actions, but this doesn’t prevent extra words. You can still enter GET THE RUSTY AXE and the parser won’t complain.
I’ve worked out that num_words returns the number of words in the input and the BeforeParsing entry point routine can be used to jump in after input, but before parsing occurs.
I tried the following, but it prints a message, then continues with the parsing:
[ BeforeParsing;
if (num_words > 2)
"You only need to enter two words.";
];
Include "parser";
[ Beforeparsing;
if (num_words > 2) {
parse-->1 = 'twomax';
parse->1 = 1;
}
];
Include "verblib";
Object room "Room"
with description "You are in a room.",
has light;
[ Initialise;
location = room;
];
Include "grammar";
[ TowWordsub;
"You only need to enter two words.";
];
Verb 'twomax' * -> TowWord;
Include "parser";
[ ParserError error_type;
if (error_type == STUCK_PE && parse->1 == 0)
"You only need to enter two words.";
rfalse;
];
[ BeforeParsing;
if (num_words > 2) parse->1 = 0;
];
Include "verblib";
Object room "Room"
with description "You are in a room.",
has light;
[ Initialise;
location = room;
];
Include "grammar";
I just think about before-routines. They return true to signal that they want to interfere and whatever the action does by default should be aborted, so naturally they must return false by default.