Inform - Resources - Examples

Starting  

Problems  
Objects  
Testing I  

Characters  
Frills  
Testing II  
References  

Alice: An Inform Tutorial

This is an introduction to the use of the programming language Inform to write interactive fiction. It can be seen as a quick course in basic features in the language, and you will probably also want to refer to the Designers Manual (DM) or Inform Beginner's Guide available in the Manuals area. It is presented here in three sections, each with the resultant source code at each stage syntax-coloured and available for browsing. Alice:An Inform Tutorial was written by Gareth Rees in April 1995 and updated to Inform 6 by Graham Nelson.

1. Introduction

This tutorial aims to give you an introduction to the use of the programming language Inform to write reasonably complex adventure games. I'm going to take a puzzle which is tricky to implement in Inform, and try to take you through the steps needed to turn it into working code.

You'll need to have the following background to appreciate this tutorial:

  • You should be familiar with adventure games. I'm going to concentrate on showing how to code objects up in Inform; if you need guidelines on designing puzzles, structuring games, and prose style, then you should read Graham Nelson's essay `The Craft of Adventure'.

  • You can already write programs in some computer language (C would be most helpful, because of the similarity between the syntax of C and that of Inform).

  • You have read (even if you haven't fully understood) Graham Nelson's The Inform Designer's Manual which describes the Inform language in detail. References to sections in the Designer's Manual are given like `(DM4 S14)'.

  • You need to have release 6.01 or later of the Inform compiler and revision 6/1 or later of the Inform library in order to compile and run the examples.
This tutorial will start to write an adventure game based upon the children's novel Through the Looking Glass by Lewis Carroll. Carroll died in 1898, so the novel is out of copyright, and I will be free to steal shamelessly from it.

2. Before starting to program

Interactive fiction authors differ on how much planning you should do before you start to write code. Some people like to plunge straight into the coding process with just the vaguest idea in their heads; others prefer to plan in enormous detail before they turn their computer on. Here I'll take the approach of sketching out the solution to a puzzle in advance, and filling in the details when I write the code.

Through the Looking­Glass starts out in a room in Alice's house, in which Alice is playing with two kittens, one black and one white. The text mentions an arm­chair, a ball of worsted, a fireplace, a hearth­rug, a chess set (with red and white pieces), a clock, a cat called Dinah, and a looking­glass above the fireplace. It should be possible to involve many of these objects in the puzzle.

The puzzle will be to get through the looking­glass. How can that be made difficult? Perhaps the mantelpiece is too high for Alice to climb up onto without a chair, and the arm­chair needs to be pushed over to the mantelpiece. But the kittens get in the way of the chair, and Alice wouldn't want to hurt them, would she? So she has to distract the kittens by getting one of them tangled up in the ball of worsted, and giving the other one a chess piece to play with. The chess pieces have become lost, but she can find the red queen under the hearth­rug.

That seems like enough complexity for the first room of a game.

3. Getting started: the outline of a game

I won't try to design all those objects at once; instead I'll start out with a minimum of code and slowly add complexity to it. The idea will be that as often as possible I will have a game that I can compile and play to check that I'm proceeding along the right lines. Frequent checking of code is very important, unless you're a very skilful programmer, because adventure games involve very complicated interactions between the states of different objects, and it's very easy to forget something, or fail to check for some case, especially since you probably don't know in very much detail what the library is doing behind your back.

My first attempt is nothing more than a few simple modifications to the simplest possible Inform game (see (DM4 S4)).

Constant Story "THROUGH THE LOOKING GLASS";
Constant Headline "^An Interactive Tutorial^by Gareth Rees^";
Constant DEBUG;
The `Story' and `Headline' constants are printed by the library in the opening banner. The `DEBUG' constant gives me access to some debugging commands while testing (that line should be removed or commented out when the game is eventually released).
Include "parser";
Include "verblib";
Include "grammar";
The Inform library is broken up into three parts: the Parser, the Verb Library, and the Grammar. The reason why it is split into parts is that it may be necessary to set constants or define functions after including one library and before including the other (DM3 A11).

I need at least one object to be able to compile and run a game, so I define the initial location.

Object  Drawing_Room "Drawing room"
 has    light
 with   name "snow",
        description "The gentle sound of snow against the window pane
            suggests that it's cold outside, and you're glad to be here
            in the warmth. The drawing-room is reflected in the large
            looking-glass on the wall above the mantelpiece, and a very
            comfortable room it is too, with a warm hearth, a soft rug,
            and an arm-chair that you can curl up and sleep in.";
Note that this room description mentions a number of objects; when I define these objects I'll give them the `concealed' or `scenery' attributes to stop the library from mentioning them twice - I want to avoid output like the following.
    ... The drawing-room is reflected in the large looking-glass ...

    You can also see a looking-glass here.
The only obligatory piece of code is the `Initialise' function, which sets the location of Alice to the initial room, and prints a welcoming message (traditionally preceded by a handful of newlines because of a bug in the now little-used ITF Infocom interpreter, which doesn't display anything until it starts to scroll the screen, which is after printing 20 lines or so).
[ Initialise;
    location = Drawing_Room;
    print "^^^^^It's a cold winter day outside, but in the looking-glass
        house it's summer. All you need to do is pretend there's a way of
        getting through into it somehow...^^";
];
This gives me a program, alice1.inf (browse | download), that can be compiled and tested, although it doesn't do very much yet.

Continue to section 4.

Contents

  1. Introduction
  2. Before starting to program
  3. Getting started: the outline of a game
  4. Common difficulties
    1. Return codes
    2. Evaluation order
  5. Adding objects
    1. The red queen: a simple object
    2. The chess board
    3. The hearth: a scenery object
    4. The rug: a complex object
    5. The armchair
    6. The mantelpiece
    7. The mirror
    8. The ball of worsted
  6. Testing, part 1
  7. Adding characters
    1. The kittens
  8. Frills
  9. Checking the consistency of the game
  10. Testing, part 2
  11. Conclusions
  12. References


Last updated 23 June 2004. This site is no longer supported; information may be out of date.
Maintained as a historical archive by the Interactive Fiction Technology Foundation. Copyright 1993-2018 IFTF, CC-BY-SA unless otherwise noted.
This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.