Brass Lantern
the adventure game web site

Search

Write a Text Adventure With Inform 7

by Stephen Granade

Table of Contents

Text adventures were some of the earliest computer games. A generation of hackers cut their teeth on ones such as Infocom's Zork. Graphical games have long since taken over the commercial games market, but a vibrant independent community has kept text adventures, also known as interactive fiction, alive. For example, as many games were written for the 2005 Interactive Fiction Competition as Infocom wrote in ten years.

The box from Zork
Games like Infocom's Zork were big hits back in the early 1980s.

Want to write interactive fiction? You're in luck. A lot of work has gone into tools for doing so. Specialty programming languages such as TADS and Hugo are designed for the task, and are freely available. The most popular of these is Inform. The latest version of Inform, known as Inform 7 or I7, is designed to be easy for newcomers to use.

Let's find out if it really is easy to use. In this tutorial we'll use I7 to write a simple game. By the time we're done, you'll have the beginnings of your very own masterpiece.

Inform 7

I7 is a complete design system for interactive fiction. It's made up of a programming language and a front-end development environment. The programming language is based on English—if you're used to programming languages like C or Perl, be ready for a surprise. I7 uses logical rule-based programming to make things happen in the game world. You make a rule by defining when the rule should happen (like "when a player tries to pick up the porcupine") and what should happen (the player is told "Those quills are too pointy for you to do that!"). The development environment is set up like a book. On one page you write your game; on the opposing page you play it. The opposing page also includes a manual, a table of contents for your game, a list of every object in your game world, and more.

There's a lot more to I7 than that, but rather than wasting our time talking about I7, let's start writing our game. Before we begin, you'll need to grab a copy of Inform 7. It's available for Mac, Windows, and Linux.

Getting Started

For this tutorial, we'll create a simple game. Let's say that the player is on an intergalactic tour of various planets. We'll start the game on the player's spaceship-slash-cruise liner while it's en route to the first planet. Let's call the game "The Grand Tour".

Once you've installed Inform 7, start the program. Press "start a New Project". You'll need to fill in the name of your project ("The Grand Tour") and your name. Then press Start.

Tip

The Inform 7 manual is designed to introduce enough concepts early on that you can write a simple game after a few chapters, with additional chapters introducing additional features. It also has many worked examples to demonstrate how to code something. Read through the manual at your first opportunity.

On the left is where we'll write the code to our game, called the "source". At the top you'll see that I7 has already entered the game name and your name in a sentence. On the right is the manual. You'll want to read that later, but for now, just follow along with me. Just as the I7 development environment is modeled on a book, I7 in many ways treats your game as a book. The source is divided into paragraphs, with a blank line between each paragraph. You can add bibliographic data to your game to specify what year it was written, what its genre is, and more. Below the paragraph with the game's title and your name, add the following paragraph:

The release number is 1. The story creation year is 2006. The story headline is "A short I7 demonstration". The story genre is "Science Fiction". The story description is "A small example of how to write interactive fiction with Inform 7".

Games begin by printing out the game's title, author name, and story headline. Traditionally the headline gives additional information about the game. The story description is a short blurb about the game, suitable for excerpting on a web page listing many games.

Making the World

When writing interactive fiction, you usually begin by defining the game's rooms. We'll start with just a few. To make our life easy, the player will be stuck in their stateroom, which will have a main room and a bathroom.

An I7 problem report
If you mis-type while writing your game, you'll encounter a Problem report.

To make a room, you give it a name and a description. Whatever room you put first in the source is where the player will start. Let's begin with the stateroom's main room. Type the following paragraph below the game information paragraph.

The Stateroom is a room. "Staterooms aboard a spaceship, even one as luxurious as the Thaleia, are tight, cramped affairs, and this one is no exception. There is barely enough room for you and the furniture. The door to the hallway is locked tight for now. East is your bathroom."

Let's not wait any longer—try running it! Above your source is the green Go! button. Press it and the game compiles, then runs in the right pane. If instead you see a report that begins with Problem, then you've typed something wrong. Compare what you've typed with the above.

That one room isn't very exciting on its own, so let's go ahead and add the bathroom. We'll say what direction the bathroom is from the stateroom using compass directions. Start a new paragraph below the Stateroom paragraph.

The Bathroom is east of the Stateroom. The description is "Like your stateroom in smallness, only moreso. There is a mirror on one wall."

We now have two rooms connected to each other. Press the Go! button (or F5) to compile and run the game. Try going east and then west. It can be hard to keep track of where rooms are in relation to each other. The Index can help with that. On the right side of the I7 window, select the Index tab. If it's blank, hit F7 to compile your game. In the Index tab, select the World button. You should see the Stateroom and Bathroom listed with a line connecting them. You can also see that the player, listed as "yourself", starts in the Stateroom. The Index begins blank, but every time you compile your game, it's updated with new information.

Next | 1 | 2 | 3

About Us | Contact Us | Technical Info | History
Copyright © 1997-2010, Stephen Granade.