A Tale of Two Languages
Listing 1. Describing a CD Tray in Inform 7
094 The CD Tray is part of the old server. 095 The description is "It's a CD tray."
The differences between the two languages are apparent from the first lines. When starting a story in Inform 6, there are some essential housekeeping duties that need to be done at the beginning (i6:001-007) and end (i6:172-193) in order for the story to compile (Listing 2).
Listing 2. Essential Code for Compiling Inform 6
001 !% -SD 002 003 !======================================================== 004 Constant Story "The Server Room"; 005 Constant Headline 006 "^An Interactive Fiction by Daniel Bartholomew.^"; 007 Release 1; Serial "080625"; !for keeping track of releases . . 172 !======================================================== 173 ! Entry point routines 174 175 [ Initialise; 176 location = break_room; 177 "^^^^It's Saturday, a nice one at that, and you've been 178 called to fix a server. Again.^^You've had it. This 179 server is going to run Linux starting today! The process 180 will be easy, just put the disc into the server go. 181 Now where is that Ubuntu CD?^"; 182 ]; 183 184 [ Deathmessage; 185 if (deadflag == 5) print "You have won"; 186 ]; 187 188 !======================================================== 189 ! Standard and Extended Grammar 190 191 Include "Grammar"; 192 193 !========================================================
In Inform 7, the only thing that is absolutely required is the first line (i7:001). To be fair, the initialization routine in Inform 6 also includes the message that is displayed at the beginning of the game. In Inform 7 this also is there (i7:007-011), but it's not required for successful compilation (Listing 3).
Listing 3. Initial Program Code for Inform 7
001 "The Server Room" by "Daniel Bartholomew" 002 003 Include GNU GPL v3 by Free Software Foundation. 004 005 The maximum score is 6. 006 007 When play begins, say "It's Saturday, a nice one at that, 008 and you've been called to fix a server. Again. 009 [paragraph break]You've had it. This server is going to 010 run Linux starting today! The process will be easy, just put 011 the disk in the server and go. Now where is that Ubuntu CD?"
The defining of variables is similar in both versions—for instance, the maximum score variable (i6:009, i7:005). The main difference is that the Inform 6 version uses C-like syntax:
Constant MAX_SCORE = 6;
And, Inform 7 uses a sentence that reads similarly to how one would read the Inform 6 version out loud:
The maximum score is 6.
Some of the differences between versions are similarly minor. One example is the method of inserting paragraph breaks into long sections of text, such as in the description of the Server Room (i6:114-118, i7:082-086, Listing 4). In Inform 6, two carat symbols (^^) are used, and in Inform 7, the statement paragraph break enclosed in square brackets () does the job.
Listing 4. Syntax for Describing a Room
Inform 6 Version: 114 description "The fans, the lights, the chill... yep, it's a 115 server room. Full of servers from a dozen vendors, 116 each with their own quirks.^^Your attention is 117 immediately drawn to a server 2/3 of the way up rack 7. 118 The indicator light is blinking red and beeping.", Inform 7 Version: 082 The Server Room is a room. "The fans, the lights, the chill... 083 yep it's a server room. Full of servers from a dozen 084 vendors, each with their own quirks.[paragraph break]Your 085 attention is immediately drawn to a server 2/3 of the way up 086 rack 7. The indicator light is blinking red and beeping."
One big mistake I made when I started was creating everything first in Inform 7, and then creating the equivalent Inform 6 code. This proved tricky on a couple occasions—most notably with the random beeping messages that appear at every turn while you are in the server room (until you fix the server and win the game). Programming such logic is very different in each version. In Inform 7, writing this took almost no thought at all (i7:097-103). Basically, I described what I wanted to happen every turn, and Inform 7 made it happen. The Inform 6 code to do the same thing is not as advanced (i6:120-134). It's basically a case statement, but it's significantly more difficult to write in comparison (Listing 5).
- New Products
- Integrating Trac, Jenkins and Cobbler—Customizing Linux Operating Systems for Organizational Needs
- New Products
- Tech Tip: Really Simple HTTP Server with Python
- Readers' Choice Awards 2013
- RSS Feeds
- Non-Linux FOSS: Remember Burning ISOs?
- Cooking with Linux - Serious Cool, Sysadmin Style!
- EdgeRouter Lite