Weekend Projects for Armchair Developers:
Text Misadventuring (Part I)

April 14th, 2006 by Johnny

Zork IFlush from the mild success of the first article, I sat down to write the next installment of Weekend Projects for Armchair Developers. I stared blankly at the computer monitor, filled with a mild dread of what lay before me. I knew that the next programming language I had chosen would prove to be quite the thorny pickle. Browsing through the example included with the ZIP file I downloaded and thumbing through the small section in a “Retro Hacking” booklet I received last Christmas, I felt a bit overwhelmed.

Inform is an obscure language with its roots in the Infocom-brand text adventures of a bygone era. Growing up with such classics as Zork and Hitchhiker’s Guide to the Galaxy, I was no stranger with their work. And it was this feeling of nostalgia that drove me through the task of deciphering this seemingly-apocryphal language.

The Inform community is notoriously small. At last count, I believe there were about three people left. I think it might be because I personally have a tough time reading Inform (although, to be fair, I have seen tougher). But I was up for a challenge. So, flexing my typing-muscles, I dove straight into the beast.

Screencap

Finding the right files to download and learning how to use them is not an easy task. I blame the website. Fortunately, I’ve already braved the murky depths for you and found the installation notes. I would strongly suggest downloading the folder structures they provide for you, as they contain all the files you need to get started. In fact, I would strongly suggest reading the entire Inform FAQ when you get the time, but since you’re currently engaged in reading this article, that can wait.

(One more thing I’d like to note before we move on: You may have noticed that more than half of the icons on my desktop have the telltale translucency of a hidden file — like the results of an experiment gone horribly wrong. I’m proud to say that repairing the damage took a full half hour.)

After clearing up that mess, I decided a good place to start would be with the included example. I played a bit of it, got stuck, then gave up and started poring over the source code. I learned a couple things about syntax, and set to work on my own masterpiece. After typing up a fair chunk, I saved my work and ran the included batch file to compile everything:

Screencap

Obviously I did something wrong. The batch file counted about 30 errors with my code.

I later figured out what was wrong and corrected the problems – but enough about that. In what is perhaps one of the roughest transitory paragraphs ever, I’m going to talk about how Inform is sorta like Java.

Inform is sorta like Java. When I say that, I mean that it has a lot of “objects.” Typically, objects in Inform are either a room or an item in said room. Here’s an example, from the upcoming hit WPfADs: The Game.

Object  living_room "Living Room"
  with  name 'living' 'room',
        description "This is the living room. You've spent many an hour here shirking your duties as WPfADs writer and playing video games on your television's MASSIVE eight-inch display. A retractable ladder leads upwards to the attic, an open doorway leads north to the computer room, and to the east is the main hallway. On the opposite westward wall is a large window.",
        u_to attic,
        n_to comp_room,
        e_to hallway,
        w_to
            "You admire the peaceful, idyllic landscape outside your window. Your neighbors have recently started their own bed-and-breakfast, and a rustic wooden sign proudly proclaims that the 'Richards Inn' is open for business.",
   has  light;

This particular example is a room. Let’s examine it more closely, line by line, to get a feel for what it all means.

Object  living_room "Living Room"

Firstly, there’s the object declaration, followed by an arbitrary number of spaces (I prefer two), and the internal name of the object. This is used most commonly when assigning exits to other rooms, such as how the example above leads up to the “attic.” After another space is the external name of the object, which the player will see.

with  name 'living' 'room',

This is a list of all the names of the object, to be used by the player when interacting with them (i.e. “examine room”). Only one word per quotes. Rooms typically don’t have or need names, so we’ll gloss over this line until a later example.

description "This is the living room. You've spent many an hour here shirking your duties as WPfADs writer and playing video games on your television's MASSIVE eight-inch display. A retractable ladder leads upwards to the attic, an open doorway leads north to the computer room, and to the east is the main hallway. On the opposite westward wall is a large window.",

The description is seen by the player whenever he enters the room (if the “verbose” option is turned on in-game. Otherwise, only the first time the player enters). You’d want to list all the room’s exits (unless you were trying to be sneaky and deliberately hide information from the player), and any “scenery” in the room (that’s Inform-speak for an object that isn’t listed with the room’s contents, like the pretzels in Hitchhiker’s Guide to the Galaxy. Man, this paragraph has a lot of parenthetical comments).

        u_to attic,
        n_to comp_room,
        e_to hallway,
        w_to
            "You admire the peaceful, idyllic landscape outside your window. Your neighbors have recently started their own bed-and-breakfast, and a rustic wooden sign proudly proclaims that the 'Richards Inn' is open for business.",

This is where you assign exits to the room. You can either connect a room to another one, or to a chunk of text such as in this example’s west exit. The text is displayed whenever the player tries to go in that direction.

   has  light;

Add this line to give your room light. As every seasoned text adventure veteran can tell you, you can’t interact with anything in dark rooms without your lantern (although you can still bumble blindly through their exits), and in most games, staying in the dark for too long will result in being eaten by a grue.

Now let’s get a look at what an item looks like:

Object  laser_gun "atomic laser rifle" attic
  with  name 'atomic' 'laser' 'rifle' 'beam' 'gun',
        initial "A high-power atomic laser rifle is here, bolted securely to the floor.",
        description "It came with the house. You've been vaguely interested in using it, but a few weeks ago you lost the batteries to it and haven't been able to find replacements.",
   has  static scenery;

Most of this is similar to the room Object above, but with a few differences. Namely:

Object  laser_gun "atomic laser rifle" attic

The names of items that the player sees are traditionally lowercase, unlike rooms. After the external name is a space followed by the internal name of the room the object is located in.

with  name 'atomic' 'laser' 'rifle' 'beam' 'gun',

Names of the item, although consisting of only one word, can be melded together by the player in-game. For example, “eat atomic laser rifle” is syntactically just as valid a command as “eat rifle,” although this gun is sadly non-edible.

initial "A high-power atomic laser rifle is here, bolted securely to the floor.",

The initial line is optional, useful for items that require something a bit more descriptive than “there is a [object name] here.” If the item can be picked up, though (like the mushroom in Inform’s sample game Ruins), the initial description won’t be displayed after it’s picked up and dropped again.

has  static scenery;

“Static” describes an item that can’t be picked up. “Scenery” describes an item that isn’t displayed with the rest of the room’s contents (typically, something already mentioned in the room’s description — like the pretzels in Hitchhiker’s Guide to the Galaxy). [You must really love those pretzels. –Ed.] Items can have the “light” descriptor just like rooms, and there’s others, too — poke around some source code for more.

Now that we’ve looked at a few examples, I’ve got one more for you all: a bare-bones, yet working, game.

!% -SD
!%
Constant Story "WPFADS: The Game";
Constant Headline "^Like the Article, Except More Like a Game, Too^
         -Demo Version";
 
Constant MANUAL_PRONOUNS;
 
Include "Parser";
Include "VerbLib";
 
!-----------------------------------------------------!
 
[ Initialise;
    location = comp_chair;
    move comp_mouse to player;
    thedark.description =
        "It's very dark and empty in this room. Kinda like your soul. Kinda.";
];
 
!-----------------------------------------------------!
 
!-----------------------------------------------------!
 
Object  comp_room "Computer Room"
  with  name 'room',
        description "This unimaginatively named room contains, appropriately enough, a computer. Two, actually. The Macintosh is sadly nonoperational at the moment",
   has  light;
 
Object  comp_mouse "corded mouse"
  with  name 'corded' 'mouse' 'cord',
        description "It's a pretty nice mouse, as far as these things go. The right button doesn't really work that well anymore, and there's this one long scratch down the center from the time you took it camping, but all in all, it's decent.",
        before [;
            Drop:
                remove comp_mouse;
                comp_chair.u_to = comp_room;
                "You release the mouse from your iron grasp, letting it dangle absently off the desk's edge. Now you're free to move about unimpaired.";
               ];
 
Object  comp_chair "Sitting in the Chair"
  with  name 'chair',
        description "The computer monitor stares blankly, basking you with a dull lifeless glow and piercing the depths of your soul with a sense of intrigue. You've been sitting here for a while and your legs are starting to cramp up. Maybe you should get up and stretch a bit.",
        u_to
            "No good. You seem to be tethered to the computer by a strange mystical force, as if some sort of foul banshee whose long, greasy fingers stretch from the innermost depths of hell itself has bound you into place. Or perhaps it's because you've still got the mouse in your hand.",
   has  light;
 
!-----------------------------------------------------!
 
Include "Grammar";
 
!-----------------------------------------------------!

The Story and Headline variables are displayed when the game is started, and MANUAL_PRONOUNS, “Parser”, and “VerbLib” (As well as the final Include “Grammar”; line) set up everything on the text-parser side of the equation. There’s also one more thing that deserves examination:


[ Initialise;
    location = comp_chair;
    move comp_mouse to player;
    thedark.description =
        "It's very dark and empty in this room. Kinda like your soul. Kinda.";
];

This code is run when the game is first started. You set the location of the player, move any relevant items into his inventory (an item can be created without any location specified, like the computer mouse example I have above), and set a description of the “dark.” The dark’s description is displayed in any room where there is an absence of light, in lieu of the normal description.

That’s all I’ve got this time. I wanted to end this article with a bang, offering the exclusive chance to download WPfADs: The Game, but it’s taken much longer than expected, and it’s taken a bit of a back seat to other projects I’m working on. But don’t worry; I’ll finish it up as soon as possible and present it to you, dear reader. Need proof?

Screencap

As always, I’d love to hear any criticisms or compliments (emphasis on the latter) you have with this article. And, hopefully, next time I’ll have something meaningful for you at the end of it.

[ Johnny is a free-time writer who enjoys long walks on the beach, amiable conversation, and not being lynched for lame cop-outs at the end of articles. ]



One Response to “Weekend Projects for Armchair Developers:
Text Misadventuring (Part I)”

  1. Xerone Says:

    Nice article, I might have to try this…

    Can’t wait til your text adventure is done, I’m waiting for it.

    *Prints out coupon just to be sure he gets his copy.

Leave a Reply