Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read a line of input in Inform 7?

Tags:

inform7

I just want to prompt the user for a line of text in the middle of an action. The effect should be like this:

> north

The robot steps in front of you as you approach the gate.
"PAASSWAAAAWRD!!" it bellows.

Enter the password: _

At this point the game should pause and let the player try to guess the password. For example, suppose I guess “fribble”, which is not the password:

Enter the password: fribble

"WRONG PASSWAAARD!" roars the robot. "CHECK CAPS LAAAWWWWK!"

>

The behavior I want is similar to if the player consents, but I want the whole line of input, not just a yes or no.

like image 348
Jason Orendorff Avatar asked Oct 12 '12 16:10

Jason Orendorff


2 Answers

Inform offers no easy way to do this, though you might be able to get to the keyboard primitives by dropping to Inform 6.

However it is possible to achieve the desired effect:

The Loading Zone is a room. "Concrete with yellow stripes. The Hold is north."
The robot is an animal in the Loading Zone. "However, a robot the size of an Arcturan megaladon guards the way."

North of the Loading Zone is the Hold.

Instead of going north from the Loading Zone:
    say "The robot steps in front of you as you approach the gate. 'PAASSWAAAAWRD!!' it bellows.";
    now the command prompt is "Enter password: ".

After reading a command when the command prompt is "Enter password: ":
    if the player's command matches "xyzzy":
        say "The robot folds itself up into a cube to let you pass.";
        move the player to the Hold;
    otherwise:
        say "'WRONG PASSWAAARD!' roars the robot. 'CHECK CAPS LAAAWWWWK!'";
    now the command prompt is ">";
    reject the player's command.

I think this sort of thing is considered poor gameplay: it forces the player to guess, which damages the player's illusion of control and choice. The more conventional way would be to require the player to say the password:

The Loading Zone is a room. "Concrete with yellow stripes. The Hold is north."
The robot is an animal in the Loading Zone. The robot is either awake or asleep. The robot is awake. "[if awake]However, a robot the size of an Arcturan megaladon guards the way.[otherwise]A cube of metal the size of an Arctural megaladon snores loudly.[end if]".
North of the Loading Zone is the Hold.

Instead of going north from the Loading Zone when the robot is awake:
    say "The robot steps in front of you as you approach the gate. 'PAASSWAAAAWRD!!' it bellows."

Instead of answering the robot that some text:
    if the topic understood matches "xyzzy":
        say "The robot folds itself up into a cube to let you pass.";
        now the robot is asleep;
    otherwise:
        say "'WRONG PASSWAAARD!' roars the robot. 'CHECK CAPS LAAAWWWWK!'"

The commands say xyzzy and answer xyzzy and robot, xyzzy and say xyzzy to robot will all work.

like image 146
Jason Orendorff Avatar answered Nov 06 '22 14:11

Jason Orendorff


The extension Questions by Michael Callaghan will help with this. Note that you might not be able to reliably test input case sensitively.

like image 33
curiousdannii Avatar answered Nov 06 '22 14:11

curiousdannii