oreilly.comSafari Books Online.Conferences.


Natural Language Game Programming with Inform 7
Pages: 1, 2

Part 3 - ...Aimed to Describe A Radically Humanizing Interface for the Writing of Interactive Fiction

Inform 7 is an experiment in strong literate programming (LP). LP with traditional programming languages gives priority to comments and other human-readable text over source code. Nelson suggests that this doesn't go far enough, and Inform 7 closes the distance between source and comments enough to almost obviate the need for comments at all. [If you need them, put them in brackets, just like ordinary editorial sidenotes.]

Authors are encouraged to organize their code into sections, parts, or chapters--whichever makes most sense in the context of their work. Only the IDE uses these sections; they do not appear in the game. Syntatically, they're identical to the headings in this article: the word "Part," a number, a dash, and some descriptive text. You probably didn't notice them much here, which is the point of their inclusion in Inform 7--whenever possible, use existing human conventions that feel natural. There is no other way to divide the source, and especially no way to chunk the game artificially into multiple files; again, there is no concept of files at all.

A common criticism of human-centric languages such as COBOL or SQL is that they can become overly verbose. This is usually true when using natural language to express concepts that have their own specialized, compact syntax already (for example, mathematics, resulting in COBOL's ADD 1 TO INPUT GIVING ANSWER). IF communicates with the player in a human language, and there are huge benefits to tightly coupling the output (English) with the input (English-like source code):

Instead of digging at the spot when the player does not carry the
shovel: say "What, without your shovel? That won't work too well."

This code expresses the condition in plain English, and the response to the player reflects that condition clearly (if a bit testily). The intent of the code is perfectly obvious even at a cursory glance, reducing the likelihood of bugs. A statement such as does not carry also eliminates many common IF-specific errors. In other languages, authors often implement this check as "if the parent of the shovel is the player," which works fine until the player puts the shovel into the backpack. She is still carrying the shovel as a human would understand it, but the game treats possessions no differently from an abstract tree of objects, and the author needs to write code with this in mind.

This is where Inform 7 gets its biggest wins, because these are cases where natural language is more, not less, concise. For example, while there's a construct for loops, natural language inherently minimizes many common types of looping (such as Inform 6's ubiquitous objectloop):

After dropping the priceless fragile vase: 

  say "The vase shatters into a zillion worthless pieces. Scattered amidst the
  shards are [is/are list of things in the vase]." 

  [Text in brackets within quoted strings are not comments but code. This,
  however, would be a comment.]

Note also that there are no procedure names; there is no reason to name a function when you can instead describe the conditions under which to call it.

IF source usually has plenty of tedious counter variables and flags used to track the state of the game world. It's a natural concept to a programmer but a foreign one to an author, so Inform 7 rarely requires them. Instead, it knows how to count:

Instead of examining the player for the third time: say "Look, that
pimple isn't going away just by staring at it."

There is no temporary variable, if-statement, or incrementing necessary. This is part of the language because asking about the historical state of the game world is extremely common in IF.

The other obvious win is that Inform 7 is supremely easy to read, even if it's the first time you've ever seen it. This isn't as handy as it might seem initially, because most IF authors write solo and over a reasonably short period of time, so there's less opportunity to revisit old code (having forgotten how it works). One downside of that readability is it may lull you into thinking that you understand some block of code, but then you may be unable to reproduce it accurately. Inform is more finicky about English than you are, and paraphrasing is often a syntax error. For now, another downside is that only one natural language is available. No doubt someone hackish enough will port the source and an equivalent grammar to another language, but it will be a non-trivial enterprise.

Part 4 - Yes, But Does It Work?

Inform 7 has already seen a great deal of use prior to its release. Two highly respected IF authors, Emily Short and Andrew Plotkin, have done extensive work on the language. Five games with source are part of the initial release, serving both as proofs of concept and as documentation for those who learn best by example. There's no doubt that by the time this year's Interactive Fiction Competition rolls around, there will be many more Inform 7 releases in play.

That said, there's still some awkwardness in the language implementations. Even the example source does not read as fluently as it might:

Instead of sleeping: now the player is asleep; say "You drop

This makes sense in Inform, but not in English. The resemblance to natural language here is probably a liability, rather than an asset.

Inform 7 does not expose some aspects of the underlying Z-machine, but the language includes the ability to drop down into Inform 6 when needed or simply perform some heavy lifting the old-fashioned way. Even pure I7 can resemble deeply-nested C code more than Pride and Prejudice, with line after line of end if; end if; end if;.

With Inform 6 always an option and already proven, the least Inform 7 could do is help. The majority of interactive fiction games are never finished, with most of them never getting further than a few rooms because even the shortest high-quality release requires significant time. Making that time more productive will result not only in more finished games, but better games, because the kind of dynamic responsiveness that delights players can be expressed so naturally. Best of all, implementing just about anything can be fun:

A person can be vampiric or human. A person is usually human.

Visibility rule when the player is vampiric and in darkness:
  say "With your cool new vampire eyes you are able to make out..."; 
  there is sufficient light.

Outdoors is a region. Every turn when the player is vampiric and in the
Outdoors: say "The light is pretty freaking bright out here." 

Instead of examining the player when the player is vampiric: 
 say "You are a delightful porcelain white, free at last of mortal zits."

Vampiric turning is an action applying to one thing. Understand "turn [person]"
and "bite [person]" as vampiric turning. 

Check vampiric turning: 
  if the player is not vampiric then say "But you aren't a vampire!" instead;
  if the noun is vampiric then say "Duh, [the noun] is already a vampire."

Carry out vampiric turning:
  now the noun is vampiric.

Report vampiric turning:

  say "You grab [the noun] roughly and sink your teeth into the pulsing, fleshy
  neck.  The rush of power is like nothing else, except maybe when you've been
  the flyer in the basket toss during a homecoming game. [paragraph break]
  Anyway, bored now."

Part 5 - Resources

  1. The Inform 7 site, obviously, is the first place to start. From there you can read up on the theoretical basis for Inform 7 (PDF) and download Inform 7 and the I7 example games.
  2. The interactive fiction portal Brass Lantern is covering Inform 7 in depth, including a comprehensive introductory article to Inform 7 from Stephen Granade, who beta-tested I7, and a long theory piece on I7 by Emily Short.
  3. The IF community is active on the newsgroup, and also on the interactive fiction chat room ifMUD.
  4. Although there are numerous interpreters already available, two merit special mention in the context of Inform 7: Gargoyle for Windows and Spatterlight for Mac OS X both focus on rendering IF attractively, with clean typography and good visual use of any bundled graphics--perfect for IF-as-books.

Liza Daly is a software engineer who specializes in applications for the publishing industry. Currently Liza is an independent consultant and the founder of threepress, a platform to produce open source publishing tools. She has been programming interactive fiction since she was nine but no longer recommends Commodore 64 BASIC or the color pink.

Return to

Sponsored by: