Writing interactive fiction games with Inform
First posted on 01 June 2006. Last updated on 30 June 2009.
|This 3D drawing shows the layout of the Stellar Patrol Ship Feinstein in Infocom's Planetfall.|
|This blueprint shows the layout of the Deep Space Station Gamma-Delta-Gamma Class Scientific Sub-Module Scientist's Quarter Plan in Infocom's Stationfall.|
About the author
David Ledgard is the author of Spacestation. Aside from being a self-taught game designer, he is trained in high and low level computing, electronics, and robotics. He has worked in factories making infra-red hand dryers, gas detectors, Psion palmtop computers, and medical breathing ventilators. His first computer was a Commodore Vic-20 with tape player, 22 characters per line on screen, and 3.5KB of memory but with color! He currently lives in United Kingdom.
About the game
Spacestation is an interactive fiction game written using Inform, based on the transcript from Infocom's Planetfall and Stationfall created by Steve Meretzky. It is a virtual duplicate of the original transcript but with added responses, objects, and locations to make for a more rounded story. Certain elements have been changed from the original because they are either illogical or too simple. Navigation within the game has been enhanced. The sidekick character AI (Artificial Intelligence) has been expanded and new time related elements have been added. About half of the puzzles in this game are from the original.
In Spacestation, you arrive in the docking port of a space station in a space scooter and find that it is deserted except for an alien Fussbudget who you have to free from a cage. You must then explore the station, hack into the computer and escape before the reactor blows.
For more information on Spacestation and Infoscripts, visit Free Working Infocom Sample Transcripts.
In 1993, Graham Nelson created Inform—a set of programming language, compiler, and library for writing text based Interactive Fiction (IF) games. He posted a notice about this design system to the newsgroup rec.arts.int-fiction and soon it became the most popular language for authoring IF games. While other programming languages exist (and some that even have the advantage of supporting graphics), none of them have the same in-depth control as Inform has to enjoy the popularity and acceptance of the latter.
As of 2006, more than a decade later, Inform is now at version 7. The system is based on the famous Infocom Z-machine that allows games to be written in .z5 code and ported to any platform or operating system which also has the appropriate interpreter. For example, the .z5 files can currently be read using WinFrotz (Windows Frotz 2002) for the PC running under Windows. There are other interpreters in existence that support virtually all platforms available.
Inform designer's manual
Inform is free and very similar to the object orientated C++ language but with specialist features built into it for adventure gaming. It comes with a designer’s manual (4th edition) which lists all the functions of its programming language. Both HTML and PDF formats are available, making the manual easier to search. There has been a plan to publish the manual as a book but it has not received sufficient demand. Despite the extensive coverage in the manual, I frequently post to the newsgroup rec.arts.int-fiction for help with complex problems when designing my own games.
Writing a game with Inform in MS-DOS
To code my games, I use a text editor and an Inform compiler for MS-DOS. The games can then be read by an interpreter for MS-DOS. Most games can now be coded in a Windows environment as long as a MS-DOS emulated shell can be brought up, such as in Windows XP.
The trouble with coding using a text editor is that the ASCII editor can only hold 32KB (kilobytes) of text, so the programme has to be divided into many .h header files. It also has no line numbers for annotation which makes debugging after compilation difficult. Of course, dividing the programme up into a set of .h libraries makes for easier maintenance, as you do not have to look through miles of code to find the bit you want to change and you can group related rooms or puzzles into a single file.
Coding the game with Inform
There are numerous tutorial programmes available on the internet to teach you how to code a game using Inform. I have never learned object-orientated programming early in my studies, opting instead for the Transputer OCCAM parallel processing language when the option is given to me. Even so, I find Inform (6.30 is the version I am using) quite easy and intuitive to code, particularly with the help of the designer’s manual and the example programme. You can take a simple programme as I have and change it bit by bit until it becomes your game. It is very simple to code room names, descriptions, and connecting directions. Paying homage to its Infocom origin, you must remember to give it light or else no description is shown and you are likely to be eaten by a grue if coded! For example, I can create a class room for this:
class Room with name "room", has light;
Just replace Object with Room in the code. Simple!
I also have to reconfigure the system compass to accept nautical directions such as fore, aft, starboard, and port as well as cardinal directions such as n, ne, e, se, s, sw, w, nw, up, and down. For my own game Spacestation, I have to replace a lot of the standard procedures in order to mimic the style used in Infocom's Planetfall and Stationfall on which my game is based. For example, this includes the status line within the rooms (with location. e.g., on couch), score, and time (in chrons; 10,000 making up a day) while making sure the clock advances in chrons for set actions.
Disinform is an utility written by Jeremy Smith that I use to take the .z5 code and convert it to .inf source code. This then allows me to check on standard responses to a player's actions. In my game, when an object is dropped there are 4 different random responses I have to code in. I also have to change the standard rude words used in Inform into Planetfall’s equivalent "trot" and "crip".
Inform .h libraries
A number of .h standard library files for Inform have already been pre-written and tested by the IF community. They can easily be imported for use, thus saving coding time and alleviating the need by the author to test them. These include libraries that allow:
• the player to ask the NPC (Non-Player Character) to do something.
• the NPC to follow the player into another room.
• footnotes to be added to the game, akin to Infocom's The Hitchhiker's Guide to the Galaxy and Stationfall.
• the game to guess that the player wants to open a certain object with a particular key, e.g., unlock (the toolbox) (with the key).
• the game to prevent the player from taking objects that are out of reach, e.g., when sitting in a chair.
• an online hints menu (personally, I do not use this feature as I find hints ruin a game).
• an online simple graphics menu.
These libraries are listed in more detail and can be found in the IF Archive maintained by David Kinder and Stephen Granade.
Playtesting the game
Playtesters can be found by scouting in the newsgroup rec.arts.int-fiction and IF Archive. They are of varying quality. Some contribute only minimal feedback, while others obsessively thrall the game suggesting changes to the tinniest elements that no one else ever notices. They also help out with spellchecking and grammar checking. For me, my mastery of the English language has certainly improved after coding a game. A playtester I know has even worked for Infocom previously.
Writing a game using a sample transcript
My game Spacestation is based on Infocom’s Planetfall and Stationfall transcript. There are many difficult puzzles in it which have taken a lot of effort to code. The code is divided into 22 files plus 3 Inform libraries and 3 .h pre-written libraries. These can be studied in more detail by downloading the source code and reading the documentation for a general overview of what each file does. The grammar (additional commands not implemented in Inform) and standard procedures have to be changed to reflect the style in the Planetfall and Stationfall universe. Some of the commands in this game do not expend the exact number of chrons as the original. Due to a slight difference between the two game transcripts, I cannot implement them both together as such.
In particular, complex problems in Spacestation which have to be implemented include:
• a space scooter in deep space and landing in a docking port.
• hunger linked to the time you have last eaten.
• a complex computer with plug, adapter, password, keyboard, and monitor.
• a see-through force barrier into another room.
• a drink dispenser with a coin slot, buttons, tray, and an invisible coin store to take and return the money.
• a complex NPC alien sidekick who has to be freed, follows you around, sleeps, and solves a puzzle.
Coding the game with other languages
Prior to learning Inform, I have experimented with a number of high and low level computer languages, including Pascal, C, and Modula-2. In 1990, I first attempted to write this transcript in Polytechnic using Modula-2 (which is like Pascal with libraries). I managed to get the map up and running using pointers and implemented a few commands, but I ultimately failed in my effort. I have found standard Pascal unsuitable to implement all the commands and responses and too restrictive because of the non-object oriented nature of the language and its inability to divide the code into additional library files. In the end, Inform simply provides a programming environment most similar to Infocom that cannot be matched by Pascal.
Spacestation is the only game to fully implement a sample transcript from Infocom that has been previously released with its games to teach new players about IF. The project has taken many hours of work to complete with help from the IF community in solving coding problems, providing pre-coded and tested .h library functions, and playtesting the game. It is as near an exact working duplicate of the Infocom’s Planetfall and Stationfall instructional transcripts as can be achieved. On a personal level, I have fully enjoyed doing this project as I get to learn how to program a full-scale instead of a minor application. I have even won a prize for my work—a book on how to write early 2-word parser adventure games. At the least, Spacestation provides a sense of nostalgia for fans of Planetfall and Stationfall. To the fullest, it demonstrates the power of the Inform design system which any budding game designer can use to develop interactive fiction games.
"Share and Enjoy"
- - Douglas Adam - Sirius Cybernetics Corporation Nutramatic Machine, The Hitchhiker’s Guide to the Galaxy.