I’m wondering if it’s possible to execute something every prompt, not just before doing something. Here’s the code:
Include Questions by Michael Callaghan.
There is a room.
Before doing anything:
ask an open question, in text mode;
A text question rule (this is the you had better get it right rule):
if the current answer matches the regular expression "foo":
say "YOU WIN";
end the story finally.
Test me with "x self / lkjlkasjdla / foo / foo / x self / foo".
Which produces:
>test me
(Testing.)
>[1] x self
As good-looking as ever.
>[2] lkjlkasjdla
I didn't understand that sentence.
>[3] foo
I didn't understand that sentence.
>[4] foo
I didn't understand that sentence.
>[5] x self
As good-looking as ever.
>[6] foo
YOU WIN
*** The End ***
What’s happening here is that “ask an open question, in text mode;” runs once at the beginning of each action, but not actually before each prompt. From the source code of Custom Library Messages by David Fisher it looks like these messages are coming from the I6 API, through LibMsg “”, “”, etc. I don’t understand what I just said, but I’ve been digging around trying to figure it out for the past couple of hours.
Now, because of this, when an incorrect command is typed, the next response is going straight to the parser as it’s not yet time to process a new action (there was no previous one that completed), and this explains why “ask an open question” isn’t called again. Thus, the following “foo” (sent to the parser) isn’t understood, which returns another LibMsg error and this scenario repeats until the user has entered a command that the parser doesn’t reject.
I’m inclined to think this isn’t a bug in Questions nor really a bug in Inform – rather, I’m doing it wrong by saying “Before doing anything:”, when, what I really mean, is “Before any prompt:”. Does that exist?
Or, does there exist some workaround like saying, “if an invalid command is entered, just go to the next turn, treating the entered command like a noop”?