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

0 votes
180 views
asked Mar 22 in Authoring by Alex (486 points)
recategorized Mar 27 by Alex

(Question originally asked by Jason Orendorff on Stack Overflow)

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.

2 Answers

+1 vote
answered Mar 22 by Dannii (329 points)

The extension Questions by Michael Callaghan can be used for situations like this.

Some example code from the extensions documentation:

    "Open Sesame" by Michael Callaghan
    Include questions by Michael Callaghan.
    Canyon is a room. "You are at the far end of a canyon. A recent rock fall behind you prevents all further hopes of escape. A large boulder to the east emits a faint green light."
    A large boulder is a door. The large boulder is locked and closed.
    The large boulder is scenery. The description is "Inscribed in runic letters on the face of the boulder are the words 'Solve Oriel[']s Myth to find your way forward.'"
    Instead of doing anything other than examining with the large boulder:
        say "There is an aura of magic about the large boulder that prevents you doing this."
    Small cave is a room. "A flight of steps leads down into the darkness."
    The large boulder is east of the canyon and west of the small cave.
    Introduction is a scene.
    Introduction begins when play begins.
    Introduction ends when the large boulder is open.
    When introduction begins:
        follow the set open sesame rule.
    Every turn when introduction is happening (this is the set open sesame rule):
        now current question is "";
        now current prompt is ">";
        now punctuation removal is true;
        ask an open question, in text mode.
    A text question rule (this is the open sesame rule):
        if introduction is happening:
            if the current answer is "emily short":
                say "With an eerie screech, the boulder rolls to one side.";
                now the large boulder is open;
                now the large boulder is unopenable;
                exit;
            otherwise:
                parse.

0 votes
answered Mar 22 by Alex (486 points)
edited Mar 22 by Alex

(Answer by Jason Orendorff)

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.

This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...