Basic Screen Effects by Emily Short

Version 8

Waiting for a keypress; clearing the screen. Also provides facilities for changing the foreground and background colors of text, when using the z-machine. These abilities will not function under Glulx.


Chapter 1: Pauses, screen-clearing, and specially-placed text
   
Section 1.1: Clearing the screen
   
Section 1.2: Waiting for key-presses; quitting suddenly
   
Section 1.3: Showing the current quotation
   
Section 1.4: Centering text on-screen
   
Section 1.5: Customizing the status line

Chapter 2: Color effects (available on the Z-machine only)
   
Section 2.1: Changing the background color
   
Section 2.2: Changing the font color

Examples
   
A — The High Note
   
B — Pillaged Village


Basic Screen Effects implements the following effects: pauses to wait for a keypress from the player; clearing the screen; changing the color of the foreground font; and changing the color of the background. Color changes function only on the Z-machine.

Chapter 1: Pauses, screen-clearing, and specially-placed text

Section 1.1: Clearing the screen

The following phrases are defined:

To clear the entire screen of everything it contains, including the status line,

clear the screen.

To clear only one section of the screen, we also have:

clear only the main screen.
clear only the status line.

Section 1.2: Waiting for key-presses; quitting suddenly

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.

In extreme cases, we may want to end the game without allowing the player an opportunity to RESTART, RESTORE, or QUIT; to this end:

stop game abruptly.

Section 1.3: Showing the current quotation

Show the current quotation displays whatever the author has selected with "display the boxed quotation...". Ordinarily boxed quotations appear when the prompt is printed, but this allows the author to show a boxed quote at another time. To achieve a splash-screen before the game proper begins, we could do something like this:

When play begins:
     display the boxed quotation
     "What's this room? I've forgotten my compass. Well, this'll be south-south-west parlour by living room. -- Philadelphia Story";
     show the current quotation;
     pause the game.

Section 1.4: Centering text on-screen

Similarly, we can display a phrase centered in the middle of the screen but without the background-coloration of the boxed quotation, like this:

center "The Merchant of Venice";

Centering text puts the text on its own new line, since it would not make much sense otherwise. Note that centered text will always be set to fixed-width; font stylings such as bold and italic will not work. (If they did, they would throw off the centering; the screen model is insufficiently sophisticated to deal with centering non-fixed-width letters.)

If we want to make our own calculations using this information, the width of the screen can be checked at any time, like so:

if the screen width is less than 75, say "The map will not display properly until you widen your screen." instead.

Section 1.5: Customizing the status line

We can also use a variation of the center command to position text in the status line. To produce a Trinity-style status line with the location, centered:

Rule for constructing the status line:
     center "[location]" at row 1;
     rule succeeds.

For status lines of more than one row, we can create a table representing the overall appearance of the desired status line and then set that table as our status bar table. The following would build a two-line status bar with all sorts of information in it. (For a more practical demonstration involving a three-line compass rose, see the example below.)

Table of Fancy Status
left     central     right
" [location]"     "[time of day]"     "[score]"
" [hair color of the suspect]"     "[eye color of the suspect]"     "[cash]"

Rule for constructing the status line:
     fill status bar with Table of Fancy Status;
     rule succeeds.

A status bar table must always have left, central, and right columns, and we must provide the rule for constructing the status line. Otherwise, Inform will use the default status line behavior. The position of the right hand side is set to 14 spaces from the end by default (matching Inform's default status line), but it is possible to change this by altering the value of the variable called right alignment depth; so we might for instance say

When play begins: now right alignment depth is 30.

for the purpose of moving what is printed on the right side inward. Note that right alignment depth will only affect the behavior of status bar tables of the kind described here; it will have no effect on Inform's default handling of the right hand status line variable.


Chapter 2: Color effects (available on the Z-machine only)

Section 2.1: Changing the background color

To turn the background black (or red, green, yellow, blue, white, magenta, or cyan):

turn the background black.
turn the background red.

... and so on. This only applies to what is typed from that point in the game onward. If we wish to turn the entire background a new color at once (and this is usually desirable), we should set the background and then clear the screen, so:

turn the background black;
clear the screen.

Section 2.2: Changing the font color

Finally, font colors can be changed with say (color) letters, where the same range of colors may be used as for the background. So for instance

say "There is a [red letters]piping hot[default letters] pie on the table."

We should be careful with color effects. Some older interpreters do not deal well with color, and part of the audience plays interactive fiction on black and white devices or via a screenreader. The phrase "say default letters" restores whatever background and foreground are normal on this system. It is not safe to assume that the player is necessarily using one particular color scheme; black-on-white, white-on-black, and white-on-blue are all relatively common.

Finally, as hinted by the section title, these color effects only work when compiling to the Z-machine. Glulx has a different and not exactly symmetrical way of handling fonts and colors, which takes a bit more setting up; if we want color effects for Glulx, we should look at the extension Glulx Text Effects, also included with Inform.

Thanks to Eric Eve for the biplatform patches to this extension.


A
 Example The High Note

Faking the player typing a specific command at the prompt.


B
 Example Pillaged Village

A status bar showing unvisited rooms in a colored compass rose.