How do I restrict Inform 6 to two-word input?

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.";
];

Any ideas?

1 Like

There are probably better things to do!

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;
1 Like

Maybe a little better?

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";
1 Like

You can stop any action in GamePreRoutine().

1 Like

Thanks guys. Very innovative. I’ll try these tonight.

I ended up going with @fredrik’s answer, as it’s the simplest. I like simple. The final code looks like this:

[ GamePreRoutine;
  if (num_words > 2)
    "You only need to enter two words.";
  rfalse;
];

The rfalse is necessary, otherwise it seems to return true by default and you don’t see any responses at all.

2 Likes

A named procedure returns true by default in Inform, wheras a procedure in a property returns false by default.

I always get these confused.

1 Like

‘True’ procedures return ‘true’. :thinking: :wink:

1 Like

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.