Handling empty commands

Hi all, for my One Choice entry I tried to use an empty command (which normally gives the “I beg your pardon?” error) to execute a stored action instead (to allow for a walkthrough function by just hitting ENTER at every turn). I found this post: Two questions: choosing rows and empty commands - Authoring / Inform 7 - The Interactive Fiction Community Forum (intfiction.org) but the suggested workaround does not work for the version of Inform7 I am using. Is this even possible in Inform 10.1.0 or later? Or ar there better ways?

1 Like

Can you just do a version of this dumb workaround?


The Lab is a room.  The closet is east of the lab.  The ball is in the closet.

The parser error internal rule response (X) is "(continuing...)[walkthrough code]".

To say walkthrough code:
	If the player is in the closet, try taking the ball.
	If the player is in the lab, try going east;

(You can of course put anything you want into the to-say rule, I assume you’ve got like a table or something?)

EDIT: duh, you’ve got the appropriate action saved as a stored action, so that’s even easier!

1 Like

Neat concept. I’d probably write a for issuing the response text of rule.

Table of walkthrough
step (action)
yourself thinking
yourself examining yourself
yourself taking inventory

current step is initially 1.

for issuing the response text of the parser error internal rule response (X):
choose row current step in the table of walkthrough;
say "(trying [step entry])";
try step entry;
increment current step;
4 Likes

For parser errors specifically, there is a separate activity that perhaps reads a bit more nicely in code:

Rule for printing a parser error when the latest parser error is the I beg your pardon error: 

(This also has the minor speed advantage that it does not introduce a condition to be checked every time a response is printed. Not that it is likely to matter unless you create a great number of these.)

3 Likes

Thank you all for your feedback. The only thing left is the extra blank line appearing at the output whenever I want to make use of this feature. I went through my whole code again to eliminate linefeeds everywhere, but I feel this is not the way forward, especially because try looking which I eventually need will result in two blank lines afterwards. Is it not possible to do something like the TEST command does, i.e. get input from somewhere and just call upon the parser to do something with it? Then if that input would be blank, I could just replace that with a command instead.

I read through the SR but I always end up missing crucial bits on how it all fits together.E.g. I understand the reading a command routine rejects blank lines, and handles oops, again, and undo. But how it ties into things is not clear to me. If I do not need oops, again, and undo, can I not just replace this with a simpler version which does what I want?

Activities (ganelson.github.io) mentions this:

Section 3 - Command parsing

Reading a command (documented at act_reading) is an activity.
The reading a command activity is accessible to Inter as "READING_A_COMMAND_ACT".

And there it more or less stops. for me. I did find this:

Parser Template (ganelson.github.io)

§11. Reading the Command. The Keyboard routine actually receives the player’s words, putting the words in a_buffer and their dictionary addresses in a_table. It is assumed that the table is the same one on each (standard) call. Much of the code handles the OOPS and UNDO commands, which are not actions and do not pass through the rest of the parser. …

The pending command is initially "".
Rule for reading a command when the pending command is not empty:
    change the text of the player's command to the pending command;
    now the pending command is "".

In other words, when the game wants to read a command, if “the pending command” is set, it takes that command instead of asking the player to type something. It’s then run through the parser as usual. (If you want it to also print the command to the screen, add that to the rule.)

This extension is basically that, wrapped up fancier so that you can queue up multiple commands to execute one at a time if you want.

After some more discussion Daniel found this extension for me:

extensions/Nathanael Nerode/Undo Output Control-v6.i7x at a18f7f1d2b0c1aa8a93839855fd00c6d9cb537bd · i7/extensions (github.com)

This extension is just the ticket for me. Now I can add walkthrough functionality in the way I want, by pressing return.

Yep, that was my mistake—I forgot empty commands never escape KeyboardPrimitive in the first place, so “reading a command” doesn’t get run again. I worked on an extension ages ago called Empty Command Handling which fixed that; it’s very out of date, but Nathanael Nerode incorporated the relevant parts into his Undo Output Control, and that has been updated for the new versions.

So the solution to this problem is to grab Undo Output Control and use the “repairing an empty command” activity to “change the text of the player’s command to” whatever you want. Unlike “reading a command”, that activity is called from within KeyboardPrimitive, when a blank line has been found.