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.
You'll need to have the following background to appreciate this
tutorial:
Through the LookingGlass 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 armchair, a ball of worsted, a fireplace,
a hearthrug, a chess set (with red and white pieces), a clock, a cat
called Dinah, and a lookingglass above the fireplace. It should be
possible to involve many of these objects in the puzzle.
The puzzle will be to get through the lookingglass. How can that be
made difficult? Perhaps the mantelpiece is too high for Alice to climb
up onto without a chair, and the armchair 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 hearthrug.
That seems like enough complexity for the first room of a game.
My first attempt is nothing more than a few simple modifications to the
simplest possible Inform game
(see (DM4 S4)).
I need at least one object to be able to compile and run a game, so
I define the initial location.
Starting
Alice: An Inform Tutorial
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.
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.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.
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).
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.Contents
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.