Add chapter 2.
[ibg.git] / chapters / 02.rst
1 =======================
2  2: Tools of the trade
3 =======================
4
5 .. epigraph::
6
7    | *C was a captain, all covered with lace;*
8    | *D was a drunkard, and had a red face.*
9
10 Conventional -- static -- fiction can be written using nothing more than
11 pencil and paper, or typewriter, or word-processor; however, the
12 requirements for producing IF are a little more extensive, and the creative
13 process slightly more complex.
14
15 * For static fiction, you first write the text, and then you check it by
16   reading what you've written.
17
18 * For IF, you still have to write all of the text, but you also have to
19   establish what text gets displayed when.  Once you have written the
20   necessary Inform instructions, you use a **compiler** program to convert
21   them into a playable format.  The resulting information is played by an
22   **interpreter** program, which permits you to interact with your
23   developing world.
24
25 With static fiction What You Write Is What You Read, but with IF the format
26 in which you initially write the game doesn't bear much resemblance to the
27 text which the interpreter ultimately displays.  For example, the "William
28 Tell" game, in the form that we wrote it, starts like this:
29
30 .. code-block:: inform
31
32     !============================================================================
33     Constant Story "William Tell";
34     Constant Headline
35                 "^A simple Inform example
36                  ^by Roger Firth and Sonja Kesserich.^";
37
38     Include "Parser";
39     Include "VerbLib";
40
41     !============================================================================
42     ! Object classes
43
44     Class   Room
45       has   light;
46     ...
47
48 You will never need to look at it in the form produced by the compiler::
49
50     050000012C6C2C2D1EF6010A0C4416900010303230313031004253FEA90C0000
51     0000000000000000000000000000168F000000000000010200000000362E3231
52     ...
53
54 but, as you'll notice from the full transcript in "William Tell" story on
55 page 219, the player will see the following::
56
57      The place: Altdorf, in the Swiss canton of Uri.  The year is 1307, at
58      which time Switzerland is under rule by the Emperor Albert of
59      Habsburg.  His local governor -- the vogt -- is the bullying Hermann
60      Gessler, who has placed his hat atop a wooden pole in the centre of
61      the town square; everybody who passes through the square must bow to
62      this hated symbol of imperial might...
63
64 Clearly, there's more to writing IF than just laying down the words in the
65 right order.  Fortunately, we can make one immediate simplification: the
66 translated form produced by the Inform compiler -- those cryptic numbers
67 and letters held in what's known as the **story file** -- is designed to be
68 read by the interpreter program.  The story file is an example of a
69 "binary" file, containing data intended for use only by a computer program.
70 Forget all that unreadable gibberish.
71
72 So that leaves just the first form -- the one starting "``Constant Story``"
73 -- which represents the tale written as a piece of IF.  That's the **source
74 file** (so called because it contains the game in its original, source,
75 form) which you create on your computer.  The source file is a "text" (or
76 "ASCII") file containing words and phrases which can be read -- admittedly
77 after a little tuition, which is what this guide is all about -- by humans.
78
79 How do you create that source file?  Using a third software program: an
80 **editor**.  However, unlike the compiler and interpreter, this program
81 isn't dedicated to the Inform system -- or even to IF.  An editor is an
82 entirely general tool for creating and modifying text files; you've
83 probably already got a basic one on your computer (an IBM PC running
84 Windows comes with NotePad, while an Apple Macintosh has SimpleText or
85 TextEdit), or you can download a better one from the Internet.  An editor
86 is like a word-processing program such as MS Word, only much less complex;
87 no fancy formatting features, no bold or italics or font control, no
88 embedded graphics; it simply enables you to type lines of text, which is
89 exactly what's needed to create an IF game.
90
91 If you look at the game source on the previous page, or in the "William
92 Tell" story on page 219, you'll notice ``Include "Parser";`` and ``Include
93 "VerbLib";`` a few lines down from the top of the file.  These are
94 instructions to the Inform compiler to "include" -- that is, to merge in
95 the contents -- of files called ``Parser.h`` and ``VerbLib.h``.  These are
96 not files which you have to create; they're standard **library files**,
97 part of the Inform system.  All that you have to do is remember to Include
98 them in every game that you write.  Until you've a fair understanding of
99 how Inform works, you've no need to worry about what they contain (though
100 you can look if you want to: they're readable text files, just like the
101 ones this guide will teach you to write).
102
103 So, we've now introduced all of the bits and pieces which you need in order to
104 write an Inform adventure game:
105
106 * a text **editor** program which can create and modify the **source file**
107   containing the descriptions and definitions of your game.  Although it's
108   not recommended, you can even use a word-processing program to do this,
109   but you have to remember to save your game in Text File format;
110
111 * some Inform **library files** which you Include in your own game source
112   file in order to provide the model world -- a basic game environment and
113   lots of useful standard definitions;
114
115 * the Inform **compiler** program, which reads your source file (and the
116   library files) and translates your descriptions and definitions into
117   another format -- the **story file** -- intended only for...
118
119 * an Inform **interpreter** program, which is what players of your game
120   use.  A player doesn't require the source file, library files or compiler
121   program, just the interpreter and the game in compiled format (which,
122   because it's a binary file not meaningful to human eyes, neatly
123   discourages players from cheating).
124
125 All of those, apart from the editor, can be downloaded for free from the IF
126 Archive.  One approach is to fetch them individually, following the
127 guidance on Graham's page: visit http://www.inform-fiction.org/ and look
128 for the "Software" section.  However, if you're using a PC or a Mac, you'll
129 find it easier to download a complete package containing everything that
130 you need to get started.
131
132 Inform on an IBM PC (running Microsoft Windows)
133 ===============================================
134
135 Although the Windows operating system is upgraded on a fairly regular
136 basis, its basic capabilities and ways of working have remained
137 more-or-less consistent for many years.  The information here applies to
138 PCs running Windows 95 onwards.
139
140 .. rubric:: Installing and testing Inform
141
142 Follow these steps:
143
144 1. Download http://www.firthworks.com/roger/downloads/inform_pc_env.zip to
145    a temporary location on your PC.
146
147 2. Use a tool like WinZip to unzip the downloaded file, giving you a new
148    ``Inform`` folder.  Move this folder (and its contents) to a suitable
149    location on your PC -- a good place would be ``C:\My Documents\Inform``,
150    but you could also use ``C:\Documents and Settings\yourname\My
151    Documents\Inform``, ``C:\Inform`` or ``C:\Program Files\Inform``.  You
152    should now have this set of folders:
153
154    .. image:: /images/inform_pc_env.*
155       :align: center
156
157    In order to make the download small and fast, these folders include just
158    enough to get you started as an Inform designer -- the compiler and
159    interpreter programs, the library files, the ``Ruins.inf`` example file
160    from the *Inform Designer's Manual*, and a template for your own first
161    game.  A few other folders are included as placeholders where you could
162    later download additional components, if you wanted them.  As soon as
163    possible, you should download the *Inform Designer's Manual* into the
164    ``Inform\Doc`` folder -- it's an essential document to have, and has
165    been omitted from this download only because of its 3MB size.
166
167 3. To verify that the downloaded files work properly, use Windows Explorer
168    to display the contents of the ``Inform\Games\MyGame1`` folder: you will
169    see the two files ``MyGame1.bat`` and ``MyGame1.inf``:
170
171    .. image:: /images/filelist1.*
172       :align: center
173
174    ``MyGame1.inf`` is a tiny skeleton game in Inform source format.  By
175    convention, all Inform source files have an extension of .inf; Windows
176    has an inbuilt definition for ``.inf`` files, and so shows its Type as
177    "Setup Information", but this doesn't seem to matter.  If you
178    double-click the file, it should open in NotePad so that you can see how
179    it's written, though it probably won't mean much -- yet.
180
181 4. ``MyGame1.bat`` is an MS-DOS batch file (an old kind of text-only
182    computer program, from the days before point-and-click interfaces) which
183    runs the Inform compiler.  Double-click it; a DOS window opens as the
184    game compiles, and you'll see this::
185
186         C:\My Documents\Inform\Games\MyGame1>..\..\Lib\Base\Inform MyGame1
187         +include_path=.\,..\..\Lib\Base,..\..\Lib\Contrib | more
188
189         Inform 6.30 for Win32 (27th Feb 2004)
190
191         C:\My Documents\Inform\Games\MyGame1>pause "at end of compilation"
192         Press any key to continue . . .
193
194    Press the space bar, then close the DOS window.
195
196    .. note::
197
198       On Windows NT, 2000 and XP, the DOS window closes of its own accord
199       when you press the space bar.
200
201 5. A story file ``MyGame1.z5`` has appeared in the folder; this is the
202    compiled game, which you can play using an interpreter:
203
204    .. image:: /images/filelist2.*
205       :align: center
206
207    The extension of ``.z5`` signifies that the story file contains a
208    Z-machine game in Version 5 (today's standard) format.
209
210 6. Use Windows Explorer to display the contents of the ``Inform\Bin\Frotz``
211    folder, and double-click ``Frotz.exe``; the interpreter presents an
212    ``Open a Z-code Game`` dialog box.
213
214 7. Browse to display the ``Inform\Games\MyGame1`` folder, and select
215    ``MyGame1.z5``.  Click ``Open``.  The game starts running in the Windows
216    Frotz 2002 window.
217
218 8. When you tire of "playing" the game -- which won't take long -- you can
219    type the QUIT command, you can select ``File > Exit``, or you can simply
220    close the Frotz window.
221
222 9. Using the same techniques, you can compile and play ``Ruins.inf``, which
223    is held in the ``Inform\Games\Download`` folder.  RUINS is the game used
224    as an example throughout the *Inform Designer's Manual*.
225
226 .. rubric:: Setting file associations
227
228 The business of first starting the interpreter, and then locating the story
229 file that you want to play, is clumsy and inconvenient.  Fortunately, when
230 you first run the Frotz interpreter, it automatically creates an
231 association with story files whose extension is ``.z5``.  From now on,
232 you'll be able to play a game simply by double-clicking its story file.  If
233 some any reason this doesn't work, you can set up the association yourself:
234
235 1. Double-click ``MyGame1.z5``; Windows asks you to select the program
236    which is to open it:
237
238    * type ``Z-code V5 Adventure`` as the "``Description for...``"
239    * click to select "``Always use this program...``"
240    * click ``Other...``
241
242 2. Browse to display the ``Inform\Bin\Frotz`` folder, and select
243    ``Frotz.exe``.  Click ``Open``.
244
245 .. rubric:: Changing the Windows icon
246
247 If the Windows icon that's displayed alongside ``MyGame1.z5`` doesn't look
248 right, you can change it.
249
250 1. In Windows Explorer, either select ``View > Options...`` and click
251    ``File Types``, or select ``Tools > Folder Options...`` and click ``File
252    Types``:
253
254    * select the game file type in the list, which is in order either of
255      application (Frotz) or of extension (Z5)
256    * click ``Edit...``
257
258 2. In the ``Edit File Type`` dialog, click ``Change Icon``.
259
260 3. In the ``Change Icon`` dialog, ensure that the file name is
261    ``Inform\Bin\Frotz\Frotz.exe``, and select one of the displayed icons.
262    Click ``OK`` to close all the dialogs.  The files in the folder should
263    now look like this:
264
265    .. image:: /images/filelist3.*
266       :align: center
267
268 .. rubric:: Compiling using a batch file
269
270 You can view -- and of course change -- the contents of ``MyGame1.bat``,
271 the batch file which you double-click to run the compiler, using any text
272 editor.  You'll see two lines, something like this (the first chunk is all
273 on one long line, with a space between the ``MyGame1`` and the
274 ``+include_path``)::
275
276      ..\..\Lib\Base\Inform MyGame1
277                  +include_path=.\,..\..\Lib\Base,..\..\Lib\Contrib | more
278      pause "at end of compilation"
279
280 These long strings of text are command lines -- a powerful interface method
281 predating the icons and menus that most computer users know.  You won't
282 need to master the command line interface in order to start using Inform,
283 but this section will tell you what these particular command lines are
284 doing.  There are four parts to the first line:
285
286 1. ``Inform`` refers to the compiler program, and ``..\..\Lib\Base`` is the
287    name of the folder which contains it (addressed relative to *this*
288    folder, the one which holds the source file).  Double-dots stand for "go
289    to the parent folder".
290
291 2. ``MyGame1`` is the name of the Inform source file; you don't need to
292    mention its extension of ``.inf`` if you don't want to.
293
294 3. ``+include_path=.\,..\..\Lib\Base,..\..\Lib\Contrib`` tells the compiler
295    where to look for files like ``Parser`` and ``VerbLib`` which you've
296    Included.  Three locations are suggested: this folder, which holds the
297    source file (``.\``); the folder holding the standard library files
298    (``..\..\Lib\Base``); the folder holding useful bits and pieces
299    contributed by the Inform community (``..\..\Lib\Contrib``).  The three
300    locations are searched in that order.
301
302    .. note::
303
304       On the command line, you sometimes also see a compiler **switch**
305       such as ``-S``, used for controlling detailed aspects of how the
306       compiler operates.  Rather than do that here, we find it more
307       convenient to place any necessary switches at the very top of the
308       source file, as we'll explain in the next chapter.
309
310 4. ``| more`` causes the compiler to pause if it finds more mistakes than
311    it can tell you about on a single screen, rather than have them scroll
312    off the top of the MS-DOS window.  Press the space bar to continue the
313    compilation.
314
315 The second line -- ``pause "at end of compilation"`` -- just prevents the
316 window from closing before you can read its contents, as it otherwise would
317 on Windows NT, 2000 and XP.
318
319 You'll need to have a new batch file like this to match each new source
320 file which you create.  The only item which will differ in the new file is
321 the name of the Inform source file -- ``MyGame1`` in this example.  You
322 must change this to match the name of the new source file; everything else
323 can stay the same in each ``.bat`` file that you create.
324
325 .. rubric:: Getting a better editor
326
327 Although NotePad is adequate when you're getting started, you'll find life
328 much easier if you obtain a more powerful editor program.  We recommend
329 TextPad, available as shareware from http://www.textpad.com/; in addition,
330 there are some detailed instructions at
331 http://www.onyxring.com/informguide.aspx?article=14 on how to improve the
332 way that TextPad works with Inform.  The biggest single improvement, the
333 one that will make game development dramatically simpler, is being able to
334 compile your source file *from within* the editor.  No need to save the
335 file, switch to another window and double-click the batch file (and indeed,
336 no further need for the batch file itself): just press a key while editing
337 the file -- and it compiles there and then.  You can also run the
338 interpreter with similar ease.  The convenience of doing this far outweighs
339 the small amount of time needed to obtain and configure TextPad.
340
341 Inform on an Apple Macintosh (running OS X)
342 ===========================================
343
344 Whereas our instructions for using Inform on a PC apply to just about all
345 versions of Windows, on the Macintosh we need to be more precise.  Our
346 guidance here is specifically for Mac OS X, rather than for its predecessor
347 OS 9, and it may be helpful if we first mention a few relevant differences.
348
349 Mac OS X is a robust system constructed around -- or on top of -- BSD
350 [#bsd]_ UNIX.  There are several kinds of applications that will run on
351 your Mac OS X:
352
353 * Aqua: specifically designed for the Graphical User Interface of Mac OS X,
354   and taking advantage of its underlying technologies.  Broadly, there
355   are two types of Aqua application:
356
357   * Cocoa: built with programming tools designed for Mac OS X.
358
359   * Carbon: built with the programming tools designed for Mac OS 9 and
360     earlier versions, but "translated" to take advantage of OS X.
361
362 * Classic: designed to work on Mac OS 9 and earlier versions.  They need to
363   run in the Classic environment of OS X; roughly speaking, Classic is an
364   emulation of the older Mac systems.
365
366 * X11: based on a windowing system designed for the UNIX/Linux world.  They
367   need an X-Windows server to run, and their appearance and functionality
368   may seem a lot different to what the Aqua user expects.
369
370 * UNIX: most UNIX programs (including Linux) will run on your Mac OS X, but
371   they usually have to be accessed (or configured) from the UNIX core of
372   your Mac, through the Terminal utility.
373
374 These differences may be significant, since some of the tools designed to
375 develop and run IF on a Mac system (for example, ones you'll find in the
376 Archive) have been built by programmers working in different environments
377 with varying technologies.  We have tried to select tools that will make
378 your life easy as a beginner, but in time you may want to investigate
379 alternative approaches.
380
381 .. rubric:: Installing and testing Inform
382
383 Follow these steps:
384
385 1. Download http://www.firthworks.com/roger/downloads/inform_macosx_env.sit
386    to a temporary location on your Mac.
387
388 2. Use a tool like StuffIt Expander to unpack the downloaded file (if your
389    system configuration is standard, a mere double-click will make it
390    self-extract at the current location, if it hasn't already expanded all
391    by itself).  You'll now have a new ``Inform`` folder.  Move this folder
392    (and its contents) to a suitable location in your Mac.
393
394    .. note::
395
396       It is a good idea for now to place it in your home directory;
397       otherwise, a few pre-configured items may not work as explained.
398       Once you learn the basics of the configuration, you may move the
399       Inform folder to a different location and hack all the defaults like
400       the professionals do.
401
402    You should now have this set of folders:
403
404    .. image:: /images/inform_mac_env.*
405       :align: center
406
407    In order to make the download small and fast, these folders include just
408    enough to get you started as an Inform designer -- the compiler and
409    interpreter programs, the library files, the ``Ruins.inf`` example from
410    the *Inform Designer's Manual*, and a template for your own first game,
411    which you may copy and rename each time you begin a new Inform project.
412    A few other folders are included as placeholders where you could later
413    download additional components, if you wanted them.  As soon as
414    possible, you should download the *Inform Designer's Manual* into the
415    ``Inform/Doc`` folder -- it's an essential document to have, and has
416    been omitted from this download only because of its 3MB size.
417
418 3. To verify that the downloaded files work properly, use the Finder to
419    display the contents of the ``Inform/Games/MyGame1`` folder: you will see
420    the files ``MyGame1.command`` and ``MyGame1.inf``:
421
422    .. image:: /images/mac_filelist1.*
423       :align: center
424
425    ``MyGame1.inf`` is a tiny skeleton game in Inform source format.  By
426    convention, all Inform source files have an extension of ``.inf``.
427    However, Mac OS X may show its Kind as "FUJI BAS IMG document", and try
428    to open it with GraphicConverter.  If you're not a regular user of FUJI
429    BAS IMG documents, you'll probably want to change this.  Either:
430
431    * right-click on the file (or Ctrl-click)
432
433    * select ``Open with`` and choose ``Other...``
434
435    * in the ``Open with`` dialog, go to the ``Applications`` folder and
436      select TextEdit.
437
438    * click to select "``Always open with``"
439
440    * click ``Open``.
441
442    or:
443
444    * right-click on the file (or Ctrl-click)
445
446    * press Option, select ``Always open with`` and choose ``Other...``
447
448    * in the ``Open with`` dialog, go to the ``Applications`` folder and
449      select TextEdit.
450
451    * click ``Open``.
452
453    Now, if you double-click the file, it should open in TextEdit so that
454    you can see how it's written, though it probably won't mean much -- yet.
455
456    The above process may affect only this specific file.  To change the
457    program that opens by default all ``.inf`` files, try this:
458
459    * right-click on the file (or Ctrl-click)
460
461    * select ``Get Info``
462
463    * in the ``Open with`` tab, select TextEdit as the application
464
465    * click the ``Change All...`` button, and confirm the change when asked.
466
467 4. ``MyGame1.command`` is a Terminal Shell Script (a UNIX executable
468    command-line file, a kind of text-only computer program from the days
469    before point-and-click interfaces) which runs the Inform compiler.
470    Double-click it; a UNIX window opens as the game compiles, and you'll
471    see something like this (the working path will reflect your folder
472    hierarchy)::
473
474          Last login: Sat Jul 3 03:07:51 on ttyp1
475          Welcome to Darwin!
476          /Users/Dave/Inform/Games/MyGame1/MyGame1.command; [Hal:~] Dave%
477                 /Users/Dave/Inform/Games/MyGame1/MyGame1.command; exit
478          Inform 6.30 (27th Feb 2004)
479          logout
480          [Process completed]
481
482    .. todo::
483
484       Verify this output.  It's what's in the PDF, but the command prompt
485       looks like it's in the wrong place.
486
487 5. A story file ``MyGame1.z5`` has appeared in the folder; this is the
488    compiled game, which you can play using an interpreter:
489
490    .. image:: /images/mac_filelist2.*
491       :align: center
492
493    The extension of ``.z5`` signifies that the story file contains a
494    Z-machine game in Version 5 (today's standard) format.
495
496 6. Use the Finder to display the contents of the ``Inform/Bin/Zoom``
497    folder, and double-click ``Zoom``; the interpreter presents an ``Open``
498    dialog box.
499
500 7. Browse to display the ``Inform/Games/MyGame1`` folder, and select
501    ``MyGame1.z5``.  Click ``Open``.  The game starts running in the Zoom
502    window.
503
504 8. When you tire of "playing" the game -- which won't take long -- you can
505    type the QUIT command, you can select ``Zoom > Quit Zoom``, or you can
506    simply close the Zoom window.
507
508 .. rubric:: Setting file associations
509
510 The business of first starting the interpreter, and then locating the story
511 file that you want to play, is clumsy and inconvenient.  Fortunately, when
512 the system first "sees" the Zoom interpreter (which is a nice Aqua
513 application) it automatically creates an association with story files whose
514 extension is ``.z5`` (and with other Infocom formats).  From now on, you'll
515 be able to play a game simply by double-clicking its story file.
516
517 The files in the folder should now look like this:
518
519 .. image:: /images/mac_filelist3.*
520    :align: center
521
522 .. rubric:: Compiling using a command-line file
523
524 If you have followed these instructions to configure your system, every
525 time that you need to compile your source code you just have to
526 double-click on the file ``MyGame1.command``.  However, this file is good
527 only for this folder and for ``MyGame1.inf``.
528
529 If you want to start coding another game, you may copy the folder
530 ``MyGame1`` with all its contents and rename it as you please (for example,
531 ``MyGame2`` or something more appropriate).  Inside the folder, you'll also
532 want to rename the relevant files:
533
534     ``MyGame1.inf`` might become ``MyGame2.inf``, or ``MobyDick.inf``,
535     or...
536
537     ``MyGame1.command`` would change to match: ``MyGame2.command``, or
538     ``MobyDick.command``.
539
540 You can view -- and of course change -- the contents of
541 ``MyGame2.command``, the command file which you double-click to run the
542 compiler, using any text editor.  You'll see two lines, something like this
543 (the second chunk is all on one long line, with a space between the
544 ``MyGame1`` and the ``+include_path``)::
545
546     cd ~/Inform/Games/MyGame1/
547     ../../Lib/Base/inform630_macosx MyGame1
548                       +include_path=./,../../Lib/Base,../../Lib/Contrib
549
550 These long strings of text are command lines -- a powerful interface method
551 predating the icons and menus that most computer users know.  You won't
552 need to master the command line interface in order to start using Inform,
553 but this section will introduce you to a few basic concepts to get your
554 bearings.  The first line changes the working directory to
555 ``~/Inform/Games/MyGame1/``.  The command ``cd`` (also known as ``chdir``,
556 short for "Change Directory to") lets you travel to the desired folder,
557 specified by the path, in this case: ``~/Inform/Games/MyGame1/``.  The
558 ``~`` symbol stands for your home directory.  That is, if your user name
559 were Dave, the above path is equal to::
560
561      /Users/Dave/Inform/Games/MyGame1/
562
563 You want to change that line so that it reads: ``cd
564 ~/Inform/Games/MyGame2/``
565
566 There are three parts to the second line:
567
568 1. ``inform630_macosx`` refers to the compiler program, and
569    ``../../Lib/Base`` is the name of the folder which contains it
570    (addressed relative to *this* folder, the one which holds the source
571    file).  Double-dots stand for "go to the parent folder".
572
573 2. ``MyGame1`` is the name of the Inform source file; you don't need to
574    mention its extension of ``.inf`` if you don't want to.  You'll want to
575    change this to match the name of your new file: ``MyGame2``.
576
577 3. ``+include_path=./,../../Lib/Base,../../Lib/Contrib`` tells the compiler
578    where to look for files like ``Parser`` and ``VerbLib`` which you've
579    Included in the source file (this may sound confusing now, but it will
580    make a lot of sense after you've delved a bit deeper into this Guide).
581    Three locations are suggested, separated by commas: this folder, which
582    holds the source file (``./``); the folder holding the standard library
583    files (``../../Lib/Base``); the folder holding useful bits and pieces
584    contributed by the Inform community (``../../Lib/Contrib``).  The three
585    locations are searched in that order.
586
587    .. note::
588
589       On the command line, you sometimes also see a compiler switch such as
590       ``-S``, used for controlling detailed aspects of how the compiler
591       operates.  Rather than do that here, we find it more convenient to
592       place any necessary switches at the very top of the source file, as
593       we'll explain in the next chapter.
594
595 Once you've finished editing those lines, ``Save`` the file (not
596 ``SaveAs``), overwriting the original, and make sure that your text editor
597 doesn't append an extension like ``.txt`` (TextEdit, the default editor
598 that comes with OS X, is polite enough to ask you about this).
599
600 You'll need to have a new command file like this to match each new source
601 file which you create.  The only item which will differ in the new file is
602 the name of the Inform source file -- ``MyGameN``.  You must change this to
603 match the name of the new source file; everything else can stay the same in
604 each ``.command`` file that you create.
605
606 .. rubric:: Making your own command-line file
607
608 There are two peculiarities by which your system understands that
609 ``MyGame1.command`` is a Terminal Shell Script.  One is the extension
610 ``.command``, and the other is an attribute of the file which marks it as
611 "executable" (the "executable bits").  If it doesn't meet both conditions,
612 ``MyGame1.command`` won't run as it should.  You have to be careful when
613 editing this file: if you were, for instance, to open it in a text editor
614 and save it to a different location with a different name, the executable
615 bits might get lost, and when you double-click it, you would see:
616
617 .. image:: /images/mac_exec_error.*
618    :align: center
619
620 To make a command file from scratch (also, to fix this problem) you can
621 follow these steps:
622
623 1. Open any text editor and write (using your own path)::
624
625         cd ~/Inform/Games/MyGameN/
626         ../../Lib/Base/inform630_macosx MyGameN
627                       +include_path=./,../../Lib/Base,../../Lib/Contrib
628
629    where ``MyGameN`` stands for the name you have chosen for your Inform
630    project.
631
632 2. Save the file in the folder ``MyGameN`` and call it ``MyGameN.command``.
633    Make sure that the text editor doesn't append a ``.txt`` extension; if
634    it does, rename the file manually.
635
636 3. Go to ``Applications > Utilities`` and double-click on ``Terminal``.
637    This opens the utility which provides you with a set of windows to
638    access the UNIX command line.  Supposing the computer is named Hal, and
639    the user Dave, you should see something like this::
640
641         Last login: Wed Jun 30 18:05:55 on ttyp1
642         Welcome to Darwin!
643         [Hal:~] Dave%
644
645 4. Every time that you open a Terminal window, you're at your home
646    directory (as noted by the tilde after the computer's name).  You can
647    travel to your working folder by typing::
648
649         cd Inform/Games/MyGameN
650
651    You'll see how the path changes::
652
653         [Hal:~/Inform/Games/MyGameN] Dave%
654
655    Now you can make the command file executable with::
656
657         chmod 777 MyGameN.command
658
659 5. Alternatively, you can omit the cd command if you give the full path to
660    ``chmod``::
661
662           chmod 777 ~/Inform/Games/MyGameN/MyGameN.command
663
664    This sets the executable bits for the file ``MyGameN.command``.
665
666 6. Close the Terminal window.
667
668 Now, every time you need to compile your game, you can just double-click on
669 ``MyGameN.command`` from the Finder.
670
671 .. rubric:: Getting a better editor
672
673 Although TextEdit is adequate when you're getting started, you'll find life
674 much easier if you obtain a more powerful editor program.  We'd really like
675 to recommend one -- there's an exciting list of possibilities at
676 http://osx.hyperjeff.net/Apps/apps.php?sub=5 -- but at the time of writing
677 none of them seems outstandingly suited to IF authorship.  If you find one
678 that works really well, please let us know.
679
680 .. rubric:: More about the editor
681
682 As well as the ones that we recommend, other good text editors are listed
683 at http://www.firthworks.com/roger/editors/.  One feature that's well worth
684 looking out for is "hotkey compilation" -- being able to run the compiler
685 from *within* the editor.  Another is "syntax colouring", where the editor
686 understands enough of Inform's syntax rules to colour-code your source
687 file; for example: red for brackets, braces and parentheses ``[ ]`` ``{ }``
688 and ``( )``, blue for reserved words like ``Object`` and ``print``, green
689 for items in quotes like '...'  and "...", and so on.  Syntax colouring is
690 of great assistance in getting your source file correct and thus avoiding
691 silly compilation errors.
692
693 .. rubric:: More about the compiler
694
695 The Inform compiler is a powerful but undramatic software tool; it does an
696 awful lot of work, but it does it all at once, without stopping to ask you
697 any questions.  Its input is a readable text source file; the output is a
698 story file, also sometimes known as a **Z-code file** (because it contains
699 the game translated into code for the Z-machine, which we describe in the
700 next section).
701
702 If you're lucky, the compiler will translate your source file into Z-code;
703 perhaps surprisingly, it doesn't display any form of "success" message when
704 it succeeds.  Often, however, it fails, because of mistakes which you've
705 made when writing the game.  Inform defines a set of rules -- a capital
706 letter here, a comma there, these words only in a certain order, those
707 words spelled just so -- about which the compiler is extremely fussy.  If
708 you accidentally break the rules, the compiler complains: it refuses to
709 write a Z-code file.  *Do not worry about this*: the rules are easy to
710 learn, but just as easy to break, and all Inform designers inadvertently do
711 so on a regular basis.  There's some additional information about dealing
712 with these mistakes, and about controlling how the compiler behaves, in
713 "Compiling your game" on page 189.
714
715 .. rubric:: More about the interpreter
716
717 One of the big advantages of the way Inform works is that a compiled game
718 -- the Z-code story file -- is portable between different computers.
719 That's not just from one PC to another: exactly the same story file will
720 run on a PC, a Mac, an Amiga, UNIX workstations, IBM mainframes, PalmOS
721 hand-helds, and on dozens of other past, present and future computers.  The
722 magic that makes this happen is the interpreter program, a software tool
723 which pretends to be a simple computer called a **Z-machine**.  The
724 Z-machine is an imaginary (or "virtual") computer, but its design has been
725 very carefully specified, so that an expert programmer can quite easily
726 build one.  And that's exactly what has happened: a Macintosh guru has
727 built an Inform interpreter which runs on Apple Macs, a UNIX wizard has
728 built one for UNIX workstations, and so on.  Sometimes, you even get a
729 choice; for popular machines like the PC and the Mac there are several
730 interpreters available.  And the wonderful thing is: each of those
731 interpreters, on each of those computers, is able to play every Inform game
732 that's ever been written *and*, as a surprise bonus, all of the classic
733 1980s Infocom games like "Zork" and "The Hitchhiker's Guide to the Galaxy"
734 as well!
735
736 (Actually, that last sentence is a slight exaggeration; a few games are
737 very large, or have pictures included within them, and not all interpreters
738 can handle this.  However, with that small pinch of salt, it's pretty
739 accurate.)
740
741 That's enough waffling: let's get started!  It's time to begin designing
742 our first game.
743
744 .. rubric:: Footnotes
745
746 .. [#bsd]
747    "BSD" stands for Berkeley Software Distribution, the name of the UNIX
748    derivative distributed in the 1970s from the University of California,
749    Berkeley, and used collectively for the modern descendants of those
750    distributions.