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