Natural Language Game Programming with Inform 7by Liza Daly
Part 1 - Introducing Inform 7
Programming games is an activity. A programming language is a kind of thing. Inform 7 is a kind of programming language. It is either the single-most important advance in interactive fiction in a decade, or an interesting idea doomed to fail.
If you can read that, you can read Inform 7, Graham Nelson's latest version of the most popular programming language for writing interactive fiction (IF), or "text adventures." The preceding paragraph is Inform 7 source code: contrived for this article, yes, but you can compile and run it. If you are a COBOL fan, you will love this language, and if you are not, the main thing you should know is that Inform 7 does not suck. It can do real work in a novel way.
In Choosing a Language for Interactive Fiction, I compared the two most widely used interactive fiction development languages and concluded that real programmers will naturally want to use TADS 3, because it contains all of the features that are so obviously critical to writing IF:
- Heavy use of object-oriented programming
- An extremely comprehensive standard library that models the real world
- A familiar C-like syntax
By comparison, Inform 7 has:
- Rule-based semantics in place of classes, objects, and methods
- A very lightweight standard library, stripped down even relative to Inform 6
- English sentences
OK, so Graham Nelson isn't an ONLamp reader. Interactive fiction languages have tended toward greater complexity and a closer resemblance to traditional programming. What kind of a system do you get when you throw all that away and start from scratch?
Part 2 - Interactive Fiction Games Are A Kind of Book
The first principle of Inform 7 is that interactive fiction is a literary pursuit; IF works are more like short novels than games. In this white paper (PDF), Nelson writes that "the natural language in which to write interactive fiction is natural language," and he believes this statement should apply not only to the language, but to the entire development cycle. As the Macintosh computer did for the desktop metaphor, Inform 7 extends interactive fiction as writing through every aspect of the user experience. This includes not only its unique natural language syntax, but also the integrated development environment, source code organization, and library management.
Inform 7's IDE (currently available for Mac OS X and Windows) presents the developer with two panels positioned like facing pages of a book (Figure 1). There are no references to filenames, header files, or anything platform-specific. Include libraries (called extensions) by naming the library and its author; author name is a requirement because authorship is important in literature. In the default mode, you edit source code in the left pane and all IDE responses appear on the right. Tabs provide access to built-in documentation, the compiler output window, an Inform interpreter, and numerous debugging tools.
Figure 1. The Inform 7 IDE
Some of these debugging tools merit special mention. The IDE can track commands issued in a particular game session and replay them after a recompile. The Skein (Figure 2) provides a visual record of these commands and tracks threads in the story. Because the Skein can get quite large, the programmer can prune the tree to include only the main plotline and relevant branches, but then he can click on any node to jump into the game at that point. It's a unique hybrid of debugger and unit testing suite. Outside of the Skein, you can construct simple unit tests by bundling several commands into a single test. In the spirit of Perl's POD, you can even embed inline documentation and testable example code directly into the source.
Figure 2. The Skein
The IDE also generates a map for each game. The map isn't as aesthetically pleasing as a hand-authored one, and the system can run into trouble with topologically challenging games, but the feature remains quite useful. With natural language source code, it's easy to get lost in pronouns and incorrectly relate objects. The map provides instant feedback in a case where you may have intended the restrooms to be northeast of the Second Floor Hall but instead attached them to a conference room (Figure 3).
Figure 3. A map from the Inform 7 IDE
When errors in the source occur, the IDE provides hyperlinks to the offending code rather than line numbers. Error messaging is in full English and attempts to guess what the author was trying to do, although after some repetition the verbose messages can get a little maddening. Error responses in the current version were derived from beta-testing; as Inform 7 matures, the messaging will likely become more nuanced.
Traditional books get published after being written. Inform 7 likewise provides a method for publishing games, tailored to the unique needs of online release. Authors are encouraged to include metadata complete enough to generate a library card to faciliate archiving and searching. You can also designate portions of code, such as debugging routines, as "not for release," and the publisher will exclude them. Inform 7 exports to a standard IF format called Blorb, which can include images for cover art as well as links to external resources such as websites and audio files. If you choose not to create your own website for the game, you can generate one automatically out of a standard template. Inform 7 can bundle all of these resources together--plus generated walkthroughs, game source, and even a customized, annotated version of the games map (in EPS format). These features are built directly into the language.
Pages: 1, 2