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