Hello World (Inform 7)

From LiteratePrograms

Jump to: navigation, search
Other implementations: Ada | ALGOL 68 | Alice ML | Amiga E | Applescript | AspectJ | Assembly Intel x86 Linux | Assembly Intel x86 NetBSD | AWK | bash | BASIC | Batch files | C | C, Cairo | C, Xlib | Candle | Clojure | C++ | C# | Delphi | Dylan | E | Eiffel | Erlang | Forth | FORTRAN | Fortress | Go | Groovy | Haskell | Hume | IBM PC bootstrap | Inform 7 | Java | Java, Swing | JavaScript | LaTeX | Lisp | Logo | Lua | Maple | MATLAB | Mercury | OCaml/F Sharp | occam | Oz | Pascal | Perl | PHP | Pic | PIR | PLI | PostScript | Prolog | Python | Rexx | Ruby | Scala | Scheme | Seed7 | sh | Smalltalk | SQL | Standard ML | SVG | Tcl | Tcl Tk | Visual Basic | Visual Basic .NET | XSL

This short Inform 7 program prints a greeting to the console.

theory

Inform 7 is a natural language compiler for playing natural language (text adventure) games. The disadvantage of natural language specifications of formal systems is that they often lead to "guess the word" frustrations on the part of programmers. In this case it is assumed that people who are accustomed to playing guess-the-word when playing games will not be so frustrated when they find it necessary while making games.

practice

We must create at least one room, where the adventurer finds themselves at the start of the game. We use the room description to produce our greeting. Strictly speaking, perhaps we should state Its description is ... but we are allowed to elide that, and enter descriptions for objects as a string following their definition.

<<greeting>>=
The Logoi is a room. "You hear a hollow voice say, 'Hello, World'."

wrapping up

Finally, we implement a small test suite:

<<test suite>>=
Test me with "look".

and add the boilerplate project and author information. The complete file should be cut-and-pasted into the Inform 7 IDE. (Todo: find a way to import project source code)

<<hello.inform7>>=
"hello" by Dave
greeting
test suite

This produces the (rather boring) game which starts as follows:

hello
An Interactive Fiction by Dave
Release 1 / Serial number 070131 / Inform 7 build 3P53 (I6/v6.30 lib 6/10N) SD

Logoi
You hear a hollow voice say, "Hello, World".

>
Download code
Views
Personal tools