Inform: Special Input Prompts

Symptom

If an action is obviously dangerous, you might want to give the player a chance to back out.

  
! Wrong !
before [ ix;
  Push:
    print "Are you sure you want to do that?^";
    print "^>";
    ix = YesOrNo();
    if (ix)
      "Click.";
    else
      "Never mind, then.";
],

   >push button
Are you sure you want to do that?

>no
Never mind, then.

>push button
Are you sure you want to do that?

>yes
Click.

Tidy and correct, right? Well, no. Consider:

   >push button
Are you sure you want to do that?

>look
Please answer yes or no.> undo
Please answer yes or no.> quit
Please answer yes or no.> no
Never mind, then.

This may look like "dumb player syndrome" in the transcript, but think about it. The prompt printed before YesOrNo() looks exactly like a normal command prompt. It's quite reasonable that a "look" command should work. And certainly "undo" is a habitual way to back out of screwed-up or dangerous situations. The player might try "save" as well, or some entirely different command.

By the time the player looks at the screen and realizes that he's in a special prompt, he's pissed.

Easy Solution

Use a non-standard prompt.

  
before [ ix;
  Push:
    print "Are you sure you want to do that?^";
    print "Enter yes or no:>";
    ix = YesOrNo();
    if (ix)
      "Click.";
    else
      "Never mind, then.";
],

   >push button
Are you sure you want to do that?
Enter yes or no:>no
Never mind, then.

The prompt shown is chosen to be similar to the "Please answer yes or no" library message. If you use a different prompt, you may want to change that message too. (For inadequate reasons, it's Quit 1.)

Clever Solution

Using YesOrNo() has an unobvious drawback. If the player types "undo" after the command, the game jumps back to before the command that called YesOrNo(). This is unintuitive; normally "undo" jumps back one input, not two.

A nicer approach is not to use YesOrNo() at all. Instead, watch for a Yes or No action on the next turn. This allows the player to type any command, including "undo" or "save", and the parser will behave in the expected way.

The code for this is left as an exercise. Sorry. :)

Prevention

If you use YesOrNo(), or any other routine that prompts for a special input, make sure the player can tell he's not at a regular command prompt.


More Inform Tricks