Press Enter to continue the scene

When Runaway begins:
	say "You decide to run away.";
	move player to the Living Room;
	say "You run through the Living Room in the hopes of getting away from the ghost. You cross the room, reaching for the doorknob.";
	move the player to the Hallway;
	say "You make it to the Hallway, where you find yourself trapped, haunted by the ghost from one side and blocked by the blizzard from the other.".

How could I write this code so that the player has to press enter before some of the steps happen? For example:

You decide to run away.

[PRESS ENTER KEY]

Living Room
You run through the Living Room in the hopes of getting away from the ghost. You cross the room, reaching for the doorknob.

[PRESS ENTER KEY]

Hallway
You make it to the Hallway, where you find yourself trapped, haunted by the ghost from one side and blocked by the blizzard from the other.

1 Like

Emily Short’s “Basic Screen Effects” extension is built into Inform 7 and gives several different ways to do this. Include it in your source text with

Include Basic Screen Effects by Emily Short.

The Recipe Book 4:5 demonstrates usage: http://inform7.com/book/RB_4_5.html

Section: Waiting for key-presses

To produce a pause until the player types any key:

wait for any key.

To produce a pause until the player types SPACE, ignoring all other keys:

wait for the SPACE key.

To give the player a message saying to press SPACE to continue, wait for a keypress, and then clear the screen before continuing the action:

pause the game.

You can download or read more about the extension here.

4 Likes

It’s a pretty handy extension. You can also use it to reconstruct the status line to show available exits, other info.

If I’m not mistaken, Basic Screen Effects has only Wait for any key and Wait for the SPACE key built in, and waiting for any other specific key would require you to modify the extension in I6? But you probably want one of those two anyway, since they’re the conventional ones that players will expect.

You can in fact wait for other keys with the extension. If you make a reference to the chosen letter, the game will wait for a key and return its key code.

The following will wait for a key and print its code:

When play begins:
    let keycode be the chosen letter;
    say "The code of the pressed key is [keycode].".

With Glulx, the code for Enter is -6, so you could write:

To wait for the Enter key:
    let keycode be 0;
    while keycode is not -6:
        let keycode be the chosen letter;

I don’t remember if it’s documented.

1 Like

A few side observations:

You can use the ‘chosen letter’ code to build a whole keypress-driven CYOA in Inform if you want. Not that many (any?) people want, and the main drawback is that the keypresses solicited this way don’t go on the automatic UNDO stack.

Still, I’ve always found it easier to create menu-choice moments within a parser game using the keypress code than by going via the parser itself or using typical extensions. At least until Zarf made the UGI extension. And even then, it’s still easier for easy cases. Just more hacky, in the eyes of hacky-frowners. I ported a CYOA Apple II game I made as a kid into Inform using the keypress way. https://wadeclarke.com/ifdemos/time_warp/index.html

-Wade

1 Like