OK, this might be what you want? Getting the last input to appear again is easy once you’ve stored it, but redoing the last command seems non-trivial. You can store it as a stored action, but sometimes the last input will yield a parser error, which won’t give you an action to store. So I just decided to trap that case by setting the last command to a dummy action whenever a parser error happened. (You could give different responses to different parser errors, depending on how much you like typing, I guess.)
There may be problems with this. Also, note what happens when you try “xyzzy” after “again.” (If you want to paste this into the IDE, hit “reply,” copy the text within the code tags, and then cancel your reply – that’ll preserve the tab stops.)
[code]“Force Command” by Matt Weiner
Include Basic Screen Effects by Emily Short.
Holodeck is a room. “It’s a holodeck. A screen reads, ‘Type XYZZY to repeat your last command.’” Engine Bay is north of Holodeck. “It’s an… engine bay?” A wrench is in Engine Bay. Airlock is north of Engine Bay. “It’s an airlock, I guess.”
Erring is an action applying to nothing. [No understand grammar, no rules, no nothing; this is a dummy action that keeps track of whether the last thing entered was a parser error.]
The last input is an indexed text that varies. The last input is usually “”.
The last command is a stored action that varies. The last command is usually the action of erring.
Rule for printing a parser error:
now the last command is the action of erring;
continue the action.
To force command:
say the command prompt;
let N be the number of characters in the last input;
repeat with M running from 1 to N:
wait for any key;
say character number M in the last input; [This means whatever the player types turns into the last input]
wait for any key;
if the last command is the action of erring:
say “[line break]That won’t work this time, either.”;
otherwise:
try the last command.
Before reading a command:
now the last input is the player’s command.
xyzzying is an action applying to nothing. Understand “xyzzy” as xyzzying.
Every turn while the current action is not the action of xyzzying:
now the last command is the current action.
Carry out xyzzying:
if the last input exactly matches the text “xyzzy”:
say “You try to repeat repeating the last command, and get thoroughly confused.”;
otherwise:
say “OK, let’s try that again.”;
say line break;
force command.
Test me with “sing/xyzzy/xyzzy/n/xyzzy/get wrench/xyzzy/n/xyzzy/s/get wrench/xyzzy/go north/again/xyzzy”. [If you try “test me” the commands in the test will appear automatically, but you’ll have to enter the fake commands that are prompted by “xyzzy” yourself.][/code]