Inform: Writing Interactive Fiction Games

If you have been a computer gamer for any large length of time, you probably have stumbled across the genre of games noted as “interactive fiction”. Games such as the ever-popular Zork are text-based (meaning you have to use your imagination, kiddies). Usually you are given a bit of exposition, a description of your current scenery, and then you are prompted with a command line.

The commands you issue are pretty much natural language. For example, if you see that there is a trophy inside of a trophy case and you want to get it, you might issue the following commands:

open case
get trophy

Recently I have discovered that there is a large semi-underground pool of people still developing these type of games, even amidst the surge of 3D shooters and MMORPGs. And some of the development environments are astonishingly descriptive and easy to use.

As I started browsing the world of interactive fiction, it didn’t take long for me to stumble across Inform, which is a design system for games. The latest version (Inform 7) utilizes a domain-specific language (DSL) that allows you to create a game in plain English. The syntax is so fluid that you only need a basic set of documentation to get going and you can intuit a lot of the commands that are available. Even so, the documentation and examples provided in the system are incredibly verbose, detailed, and helpful.

Inform is an object-oriented language to some extents. The base object is a “thing” and you can create “things” to populate your game world with. Here is an example I came up with:

[code]Heat is a kind of value. The heats are cold, cool, room temperature, and warm.

A beverage is a kind of thing. A beverage can be openable or unopenable. A beverage is always edible and openable. A beverage has heat. A beverage is usually cold. A beverage can be full, partly drained, or empty. A beverage is usually full.[/code]

First off I define what is basically a set of values (like an Enumeration in Java) to describe heat. Then I construct a beverage object by saying it is “a kind of thing”. Then I assign attributes to it, such as making it a container, making it edible, giving it a heat attribute, etc.

You can also create methods for your beverage, such as handling drinking the beverage:

[code]Instead of drinking a beverage when a beverage is empty:
say “There is no more! You drank it all!”

Instead of drinking a beverage: if the beverage is partly drained, change the beverage condition to empty; if the beverage is full, change the beverage condition to partly drained; say “You drink a long draught. Refreshing!”[/code]

This uses the phrase “instead of” to override the default behavior for a thing whenever the player tries to issue the “drink” action. With this in place, you can drink a beverage until it is empty, then you will be told “There is no more! You drank it all!”

With a beverage object in hand, you can now easily “instantiate” a beverage it by saying simply:

The Mug of Ale is a beverage.

To see the expresiveness of this language, here is a complete example:

[code]“Example” by “Tim Gourley”.

The story headline is “This is an interactive example”.

Part 1 - Objects

Chapter 1 - Definition of some basic objects

Heat is a kind of value. The heats are cold, cool, room temperature, and warm.

A beverage is a kind of thing. A beverage can be openable or unopenable. A beverage is always edible and openable. A beverage has heat. A beverage is usually cold. A beverage can be full, partly drained, or empty. A beverage is usually full.

Instead of drinking a beverage when a beverage is empty:
say “There is no more! You drank it all!”

Instead of drinking a beverage: if the beverage is partly drained, change the beverage condition to empty; if the beverage is full, change the beverage condition to partly drained; say “You drink a long draught. Refreshing!”

After printing the name of a beverage: say ” ([beverage condition])”

Before printing the name of a beverage (called the drink):
say “[heat of the drink] “

Part 2 - The Game World

Chapter 1 - Inside The Tavern

The Tavern is a room. “Before you is a bustling tavern with people going to and fro. The atmosphere reminds you of home and you are quite at ease. Apparently, there are no exits so you must remain here forever.”

The Mug of Ale is in the Tavern. The Mug of Ale is a beverage.[/code]

Now I can compile this code in Inform 7, which will produce “Z-machine” code and can be run with any interpreter, such as the frotz interpreter. Here is what the game looks like when run:

Example
This is an interactive example by Tim Gourley
Release 1 / Serial number 070806 / Inform 7 build
4U65 (I6/v6.31 lib 6/11N) SD

Tavern
Before you is a bustling tavern with people going to
and fro. The atmosphere reminds you of home and
you are quite at ease. Apparently, there are no exits
so you must remain here forever.

You can see a cold Mug of Ale (full) here.

>get mug
Taken.

>drink mug
You drink a long draught. Refreshing!

>drink mug
You drink a long draught. Refreshing!

>drink mug
There is no more! You drank it all!

>

Very interesting, wouldn’t you say?

One Response to “Inform: Writing Interactive Fiction Games”

  1. BJ Says:

    In for interactive Harry Potter fanfic!!!

Leave a Reply

You must be logged in to post a comment.