The Inform 6 Programmer's Guide

Chapter 21: Printing and Output

This chapter is the definitive reference for producing textual output. It covers the print statement and its format specifiers, the library's print-rule system for articles and pronouns, object-listing routines, text styling, narrative voice and tense, and the library message customization mechanism. Where §5 introduces print and print_ret as language statements, this chapter examines the full breadth of the output system - from low-level VM opcodes to high-level library routines that automatically conjugate verbs across person and tense.

21.1 The print Statement and Format Specifiers

The print statement outputs one or more items, separated by commas:

print "The treasure is worth ", score, " points.^";

Each item is one of three kinds:

  1. A string literal in double quotes - printed directly to the output stream.
  2. An expression - evaluated, then printed as a signed decimal integer.
  3. A format specifier of the form (rule) value - calls a routine or compiles a specialized VM opcode to format the value.

The print_ret statement prints its items, outputs a newline, and returns true. It is exactly equivalent to:

print items...; new_line; rtrue;

The standalone new_line; statement prints a newline character. See §5 for the full statement-level syntax of print and print_ret.

Built-in Format Specifiers

The following specifiers are compiled directly to VM opcodes rather than function calls. They are part of the language, not the library:

Specifier Opcode Effect
(string) addr print_paddr Prints the string at packed address addr
(char) expr print_char Prints the character with ZSCII/Unicode value expr
(address) expr print_addr Prints the Z-encoded string at byte address expr (dictionary words, Lowstring constants, etc.)
(object) expr print_obj Prints an object's short_name via the raw VM opcode

A bare expression (without a format specifier) is printed as a signed decimal integer via the print_num opcode.

The (object) specifier invokes the VM opcode directly; it prints the short name without any article logic. Game code rarely needs it - use (name), (the), or (a) instead (see §21.2).

The (property) prop specifier calls the Print__PName veneer routine to print the compiler's internal name for a property. It is primarily a debugging aid: in builds with the symbol table omitted, it prints a numeric placeholder (e.g. <number 7>) instead of the property name.

String Escape Sequences

Inside double-quoted strings, the following escape sequences are recognized:

Sequence Meaning
^ Newline
~ Double-quote character (")
@@ nnn Character by decimal ZSCII value (e.g. @@64 for @)
@{ hex } Character by Unicode hex code point (e.g. @{E9} for é)
@( N ) Dynamic string interpolation (see §21.11)

21.2 Print Rules

A print rule is a routine invoked through the print statement using the syntax (routine_name) value. The compiler translates this into an ordinary function call:

print (the) lamp;    ! compiles to: DefArt(lamp);
print (MyRule) x;    ! compiles to: MyRule(x);

The routine receives one argument and is expected to print output. Its return value is discarded. This mechanism allows the library to provide a rich set of formatting routines that integrate seamlessly with print syntax.

Veneer-Provided Print Rules

The following print rules are generated by the compiler's veneer - small support routines emitted automatically. They are always available, even without the library:

(name) obj - Calls the PrintShortName veneer routine. Prints the object's short_name property if it is a string, or calls it if it is a routine, or falls back to the internal compiler name. No article is printed.

(the) obj - Calls the DefArt veneer routine. Prints the definite article "the" followed by the short name. If the object has the proper attribute (see "The Article System" below), no article is printed - the short name alone appears.

(The) obj - Calls the CDefArt veneer routine. Like (the) but capitalizes the article: "The lamp" vs "the lamp". For a proper noun, no article is printed, but (The) still capitalizes the first letter of the short name, whereas (the) leaves it as written.

(a) obj / (an) obj - Calls the InDefArt veneer routine. Prints the indefinite article "a" or "an" followed by the short name. If the object has an article property (see below), that string is used instead. If the object has the proper attribute, no article appears.

(A) obj - Calls the CInDefArt veneer routine (available since compiler 6.30). Capitalized indefinite article: "A lamp" or "An elephant".

(number) n - Calls the EnglishNumber veneer routine. The veneer's default implementation prints the number as decimal digits (equivalent to print_num). When the standard library is included, it provides its own EnglishNumber that overrides the veneer's default stub by delegating to LanguageNumber() from english.h, which prints the number as English words: print (number) 42; produces "forty-two".

The Article System

The definite and indefinite article rules respect several properties and attributes on the printed object:

  • proper attribute - suppresses all articles. Give this to named characters, place names, and other proper nouns: without proper, the library prints "a lamp" or "the lamp"; with it, just "Captain Marsh" or "Excalibur".
  • article property - overrides the default "a"/"an" (the property's default value is "a"). Set it to "some" for mass nouns ("some water"), "an" to force "an" where the default heuristic fails, etc.
  • articles property - an array of three strings providing gendered definite/indefinite articles for languages with grammatical gender. The format is language-dependent; see the language definition file for details. Not used in the standard English library.
  • short_name property - if a string, it is the printed name. If a routine, it is called and must print the name itself (return true to signal completion; return false to fall back to the name given in the object header). Default: 0, meaning the object-header name is used.
  • short_name_indef property - if provided, this alternative short name is used when an indefinite article is printed. When 0 (the default), short_name serves both contexts.

21.3 Custom Print Rules

Any routine that accepts a single argument can serve as a print rule. The compiler generates a function call:

[ Bold obj;
    style bold;
    print (name) obj;
    style roman;
];

! Usage:
print "You can see ", (Bold) shiny_thing, " here.^";

The routine should print its output and need not return any particular value.

Library-Defined Print Rules

The standard library (via english.h) defines print rules for pronouns, copulas, and other grammatical constructs. All of these automatically handle narrative voice (first/second/third person), tense (present/past), and the animate, female, male, neuter, and pluralname attributes (§17.12).

Rule Purpose Example (2nd person)
(ItOrThem) obj Objective pronoun "it", "him", "her", "them"
(ThatOrThose) obj Demonstrative pronoun "that", "him", "her", "those"
(CThatOrThose) obj Capitalized demonstrative "That", "He", "She", "Those"
(CTheyreOrThats) obj Subject + copula contraction "That's", "He's", "They're"
(IsOrAre) obj Copula verb "is", "are" (or "was", "were")
(OnesSelf) obj Reflexive pronoun "itself", "himself", "herself"
(Possessive) obj Possessive adjective "its", "his", "her", "their"
(PossessiveCaps) obj Capitalized possessive "Its", "His", "Her", "Their"
(theActor) obj Actor pronoun (lowercase) "I", "you", "he", "she"
(nop) x No-op; absorbs return value (nothing printed)

The (nop) rule is occasionally useful for discarding a function's return value inside a print statement without generating output.

21.4 WriteListFrom() and Object Listing

The WriteListFrom() routine is the library's general-purpose object lister. It produces formatted lists of objects for inventories, room descriptions, and container contents.

Signature

WriteListFrom(obj, style, depth)
  • obj - the first object to list, typically child(container). The routine traverses the sibling chain from this object onward.
  • style - a bitmask of list style flags (see §21.5).
  • depth - the initial indentation level; typically 0 for top-level lists or 1 when called recursively.

Returns 0 if no objects were listed, or true (1) if at least one object was printed.

Before producing output, WriteListFrom calls SortOutList() to reorder objects according to their list_together property so that grouped items appear adjacently.

Internal Helper Routines

  • NextEntry(o, depth) - advances to the next listable sibling, skipping objects that are concealed, scenery, or otherwise filtered out by the current style flags.
  • WillRecurs(o) - returns true if the object's contents should be recursively listed (the object is transparent, is an open container, or is a supporter).
  • ListEqual(o1, o2) - returns true if two objects should be grouped into a single count ("three gold coins") based on matching name and parse_name (compared via Identical), and, in inventory styles, matching worn, light, and container/open state.

When identical objects are counted together, the plural property - a dictionary word or routine giving the plural form of the object's name

  • supplies the printed plural, so several Coin objects with plural 'coins' can be listed as "three coins" instead of separately.

The list_together Property

When multiple objects share the same list_together value, they are grouped in listings. The value can be a string, a routine, or a number; objects with the same value form one group.

If list_together is a string, it serves as the group name header. Objects with list_together "gold coins" produce output like "three gold coins".

If list_together is a routine, it is called at two stages during listing. The global inventory_stage indicates which stage:

  • inventory_stage == 1 - print the group header. Return false to fall through to the default header.
  • inventory_stage == 2 - print the group body/details. Return false for default treatment.

The global listing_together is set to the first object in the current group, and listing_size holds the number of objects in the group.

The invent property

The invent property is called during inventory listing for each object, again using inventory_stage:

  • inventory_stage == 1 - called before the object's name is printed. Return true to print entirely custom text (suppressing the default name).
  • inventory_stage == 2 - called after the name is printed. Return true to suppress default annotations such as "(worn)" or "(providing light)".
Object -> magic_ring "magic ring"
    with name 'magic' 'ring',
         invent [;
             if (inventory_stage == 2) {
                 if (self has worn) print " (glowing softly)";
                 rtrue;
             }
         ],
    has  clothing;

21.5 List Style Flags

The style argument to WriteListFrom() is a bitmask of the following constants. Combine them with + or bitwise |.

Constant Value Effect
NEWLINE_BIT $0001 Print a newline after each entry
INDENT_BIT $0002 Indent each entry by depth level
FULLINV_BIT $0004 Full inventory annotation after each entry
ENGLISH_BIT $0008 English sentence style: commas and "and"
RECURSE_BIT $0010 Recurse into contents using visibility rules
ALWAYS_BIT $0020 Always recurse regardless of visibility
TERSE_BIT $0040 Terse style: parenthetical contents
PARTINV_BIT $0080 Brief annotations: "(providing light)", "(which is closed)"
DEFART_BIT $0100 Use "the" instead of "a"/"an"
WORKFLAG_BIT $0200 At top level, list only objects with workflag set
ISARE_BIT $0400 Print "is" or "are" before the list
CONCEAL_BIT $0800 Omit concealed and scenery objects
NOARTICLE_BIT $1000 Print no articles at all
ID_BIT $2000 Print object ID numbers (debugging)

Common Combinations

! Standard room description listing:
WriteListFrom(child(location),
    ENGLISH_BIT + RECURSE_BIT + PARTINV_BIT + TERSE_BIT
    + CONCEAL_BIT + WORKFLAG_BIT);

! Verbose inventory:
WriteListFrom(child(player),
    ENGLISH_BIT + RECURSE_BIT + FULLINV_BIT + CONCEAL_BIT);

! Indented tree-style listing:
WriteListFrom(child(container),
    NEWLINE_BIT + INDENT_BIT + RECURSE_BIT + CONCEAL_BIT);

! Simple "is/are" list for container contents:
WriteListFrom(child(box),
    ENGLISH_BIT + RECURSE_BIT + PARTINV_BIT + TERSE_BIT
    + CONCEAL_BIT + ISARE_BIT);

The first combination is close to what Look uses for listing miscellaneous objects in a room. The WORKFLAG_BIT restricts the top-level list to objects explicitly marked for listing by the Look routine; recursed contents are not filtered by workflag.

21.6 Box Quotations

[Z-machine] The box statement displays centered text in a bordered quotation box, typically used for epigraphs or dramatic quotations:

box "In the beginning"
    "was the Word.";

Each string argument becomes one line of the box. The compiler counts the arguments, measures the width of the widest line, and emits a call to the Box__Routine veneer routine. That routine uses the upper window and fixed-pitch font to render a centered box above the main text area.

A longer example with attribution:

[ ChapterQuote;
    box "Time present and time past"
        "Are both perhaps present"
        "in time future."
        ""
        "  -- T.S. Eliot";
];

Requirements and limitations:

  • Available on Z-machine versions 4 and above only. On version 3, the compiler issues a warning and silently discards the text.
  • The box is displayed after the next [MORE] prompt or when the player presses a key, depending on the interpreter.
  • Lines should be kept short - the box cannot exceed the screen width.
  • An empty string "" produces a blank line within the box.

[Glulx] The box statement compiles successfully under Glulx. The compiler-supplied Box__Routine veneer switches to the Glk block-quote style, prints the lines in order, and switches back; it does not render a centered, bordered upper window as on the Z-machine. Visual presentation depends entirely on how the interpreter's style configuration treats preformatted text, so the appearance is much less predictable than under the Z-machine model.

21.7 Text Styles

The style statement changes the visual appearance of subsequently printed text:

style bold;        ! Bold text
style underline;   ! Underlined text
style reverse;     ! Reverse video (swapped foreground/background)
style roman;       ! Reset to default (roman) appearance
style fixed;       ! Fixed-pitch (monospace) font

[Z-machine] Compiles to the set_text_style opcode. Available on version 4 and above; version 3 produces a compiler error. The Z-machine accumulates styles - issuing style bold; then style underline; produces bold underlined text. Only style roman; clears all active styles.

[Glulx] Style changes map to Glk style hints. The exact rendering depends on the interpreter's style configuration. The standard Glk styles (Normal, Emphasized, Preformatted, Header, Subheader, Alert, Note, BlockQuote, Input) do not map one-to-one to bold, underline, and reverse; the interpreter may approximate or ignore requests.

The font statement provides a simpler toggle for fixed-pitch text:

font off;   ! Switch to fixed-pitch font
font on;    ! Switch back to variable-pitch font

This is functionally equivalent to style fixed and style roman respectively, but affects only the font face without clearing other active styles.

21.8 Narrative Voice and Tense

The standard library (version 6.12.8) supports configurable narrative voice and tense. All library messages adapt automatically when you change these settings.

Setting Narrative Voice

Set player.narrative_voice in Initialise():

Value Voice Example
1 First person "I pick up the lamp."
2 Second person (default) "You pick up the lamp."
3 Third person "George picks up the lamp."
[ Initialise;
    location = StartRoom;
    player.narrative_voice = 3;
    player.short_name = "George";
    (player.&name)-->0 = 'george';
];

For third-person narration with a non-proper-noun subject, clear the proper attribute so that articles are printed:

[ Initialise;
    location = StartRoom;
    player.narrative_voice = 3;
    player.short_name = "detective";
    (player.&name)-->0 = 'detective';
    give player ~proper;
];
! output: "The detective picks up the lamp."

Setting Narrative Tense

Set player.narrative_tense to one of the following constants:

Constant Value Example
PRESENT_TENSE 0 "You pick up the lamp."
PAST_TENSE 1 "You picked up the lamp."
player.narrative_tense = PAST_TENSE;

The nameless Property

The nameless property on the player object controls how the library refers to a former player body after the player switches into a new body. It has effect only in first- and second-person narrative voices; in third person it is ignored. The default value (set by the library on selfobj) is true: when the player moves into a new object, the former body's short name is replaced by phrasing such as "your former self" (or "my former self" in first person). Set player.nameless = false and assign your own name and short_name properties to keep a custom identity for the abandoned body.

How Library Messages Adapt

All standard library messages use the CSubject helper routines (§21.9) to conjugate verbs and select pronouns. Changing narrative_voice or narrative_tense affects every message produced by the library - no additional game code is required.

21.9 CSubject Helper Routines

The CSubject family of routines handles subject-verb agreement across all narrative voices and tenses. They are used extensively in library messages and are available for game code.

CSubjectVerb

CSubjectVerb(obj, reportage, nocaps, v1, v2, v3, past)

The primary conjugation routine. Prints the subject followed by the correctly conjugated verb form.

Argument Purpose
obj The actor/subject (often actor)
reportage If true and obj is not the player, prints a reporting preamble
nocaps If true, prints lowercase "you" (for mid-sentence use)
v1 First-person present form ("close")
v2 Second-person present form (0 = same as v1)
v3 Third-person present form (0 = same as v1; often "closes")
past Past-tense form ("closed")
CSubjectVerb(actor, false, false, "close", 0, "closes", "closed");
print " ", (the) noun, ".";
! 2nd person present: "You close the door."
! 3rd person present: "George closes the door."
! 2nd person past:    "You closed the door."

CSubjectVoice

CSubjectVoice(obj, v1, v2, v3, past)

Like CSubjectVerb but prints only the verb, not the subject name. Useful when the subject has already been printed separately:

print (The) actor, " ";
CSubjectVoice(actor, "pick", 0, "picks", "picked");
print " up ", (the) noun, ".^";

Shorthand CSubject Routines

Each takes (obj, reportage, nocaps) and prints both the subject and a common auxiliary verb:

Routine 2nd Person Present Past Tense
CSubjectIs "You're" "You were"
CSubjectIsnt "You aren't" "You weren't"
CSubjectHas "You've" "You'd"
CSubjectWill "You'll" "You'd"
CSubjectCan "You can" "You could"
CSubjectCant "You can't" "You couldn't"
CSubjectDont "You don't" "You didn't"

Additional Helper Routines

Tense(present, past) - prints the present string if the current tense is present, or the past string if past. If past is false, nothing is printed in past tense.

SubjectNotPlayer(obj, reportage, nocaps, v2, v3, past) - handles subject-verb agreement for NPC subjects specifically.

theActor(obj) - a print rule that outputs the lowercase subject pronoun for obj: "I", "you", "he", "she", "it", "they", or "that" depending on narrative voice and the object's animate/female/male/neuter/pluralname attributes (§17.12).

SupportObj(obj, s1, s2) - prints s1 if obj is a supporter, or s2 otherwise. Typically used to choose between "on" and "in".

PluralObj(obj, s1, s2, past) - prints s1 for plural objects (those with the pluralname attribute, §17.12.2), or s2 for singular. If past is provided, it is used in past tense.

DecideAgainst() - prints the standard refusal message: "You decide that's not such a good idea." Adapts to voice and tense.

21.10 Library Messages and Customization

The library produces all textual output through a centralized message system that can be intercepted and customized per message.

How Messages Are Dispatched

  1. Library code calls L__M(##Action, n, x1, x2) where ##Action is the action constant (e.g. ##Take), n is the message number, and x1/x2 are optional parameters (usually objects).
  2. L__M sets the global variables lm_n (message number), lm_o (x1), and lm_s (x2).
  3. If a LibraryMessages object exists, its before property is called. If it returns true, it suppresses the default message.
  4. Otherwise, L__M calls LanguageLM(n, x1, x2) in english.h, which contains the default text for every message.

The LibraryMessages Object

To intercept messages, define an object named exactly LibraryMessages with a before property before including VerbLib.h:

Object LibraryMessages
    with before [;
        Take:
            if (lm_n == 1) "Grabbed.";
        Drop:
            if (lm_n == 1) "Released.";
    ];

Include "VerbLib";

Inside the before routine:

  • The action is available in sw__var (used by the action-switch syntax Take:, Drop:, etc.).
  • Test lm_n for the specific message number within that action.
  • lm_o and lm_s contain the x1 and x2 parameters passed to L__M.
  • Returning true - or printing a string with "..." (which implicitly returns true) - suppresses the default message.
  • Returning false lets the default message through unchanged.

Multiple messages for the same action can be handled in a single block:

Object LibraryMessages
    with before [;
        Take:
            switch (lm_n) {
                1: "Grabbed.";
                13: print "You pick up ", (the) noun,
                        " with great care.^"; rtrue;
            }
        Eat:
            if (lm_n == 1) {
                CSubjectVerb(actor, false, false,
                    "devour", 0, "devours", "devoured");
                print " ", (the) noun, ".^";
                rtrue;
            }
    ];

Message Numbering

Each action has numbered messages for specific situations. For example, ##Take defines:

lm_n Default Text
1 "Taken."
2 "You're always self-possessed."
3 "I don't suppose (the noun) would care for that."

The pseudo-action ##Miscellany covers general parser and system messages not tied to a specific action (e.g. "I beg your pardon?", "You can't see any such thing.", score notifications).

Finding Message Numbers

The definitive catalog of messages is the LanguageLM() routine in english.h. Each action has a switch block on lm_n; reading the source is the most reliable way to identify the number for a specific message.

21.11 Dynamic Strings and String Interpolation

Dynamic strings allow portions of printed text to be changed at runtime without rewriting entire string constants. Reference them inside double-quoted strings; the interpreter resolves them when it prints the string.

The string Statement

The string statement (introduced in §5.23) assigns a value to a numbered dynamic string slot:

Constant WEATHER_TEXT = 1;
string WEATHER_TEXT "sunny";

The slot can be reassigned at any point during execution:

string WEATHER_TEXT "rainy";

String Interpolation Syntax

Dynamic strings are interpolated inside double-quoted strings using one of two formats:

  • Legacy format: @01, @02, ..., @99 - exactly two decimal digits, supporting slots 0-99.
  • Extended format (compiler 6.40+): @(N) where N is any non-negative integer or a named Constant.
Constant WEATHER = 3;
string WEATHER "sunny";

[ ReportWeather;
    print "The weather is @(WEATHER) today.^";
];
! output: "The weather is sunny today."

string WEATHER "rainy";
ReportWeather();
! output: "The weather is rainy today."

Compiler Settings

The setting $MAX_DYNAMIC_STRINGS controls the number of available dynamic string slots. The default varies by target:

[Z-machine] Dynamic strings share the string abbreviation table. The 96 available entries are divided between $MAX_DYNAMIC_STRINGS and $MAX_ABBREVS; increasing one decreases the other.

[Glulx] Dynamic strings are stored independently of abbreviations. You can increase the default 100 slots without limit.

Use Cases

Dynamic strings are well suited to descriptions that vary with game state:

Constant DOOR_STATE = 0;
string DOOR_STATE "closed";

Object front_door "front door"
    with description "The heavy oak door is @(DOOR_STATE).",
         name 'front' 'door' 'oak',
         before [;
             Open:
                 string DOOR_STATE "open";
             Close:
                 string DOOR_STATE "closed";
         ],
    has  static door openable;

Other applications include varying NPC dialogue based on plot progression, reflecting environmental changes in room descriptions, and adapting text to player choices - anywhere a string constant needs to change without restructuring the surrounding code.

Caution: Dynamic strings are resolved at print time. If a string constant containing @(N) is stored and printed later, it will reflect whatever value slot N holds at the moment of printing, not at the moment the string was assigned. This is usually the desired behavior, but can produce surprises if the slot is shared across unrelated subsystems.