~ubuntu-branches/ubuntu/vivid/inform/vivid

« back to all changes in this revision

Viewing changes to info/inform-3

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2008-05-26 22:09:44 UTC
  • mfrom: (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526220944-ba7phz0d1k4vo7wx
Tags: 6.31.1+dfsg-1
* Remove a considerable number of files from the package
  due to unacceptable licensing terms.
* Repair library symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
This is Info file inform.info, produced by Makeinfo-1.64 from the input
2
 
file inform.texi.
3
 
 
4
 
This is the Inform Designer's Manual, third edition, 4 September 1996,
5
 
as updated 16 May 1997.  It was converted to Info by Christopher J.
6
 
Madsen <ac608@yfn.ysu.edu>.
7
 
 
8
 
Copyright 1996,1997 Graham Nelson and Christopher J. Madsen
9
 
 
10
 
Permission is granted to make and distribute copies of this manual
11
 
provided that:
12
 
 (a) distributed copies are not substantially different from those
13
 
     archived by the author,
14
 
 (b) this and other copyright messages are always retained in full, and
15
 
 (c) no profit is involved.
16
 
 
17
 
 
18
 
File: inform,  Node: Creating Objects,  Next: Using the Tree,  Prev: Object Tree,  Up: Objects
19
 
 
20
 
Creating objects 1: setting up the tree
21
 
---------------------------------------
22
 
 
23
 
   The object tree's initial state is created with the directive
24
 
Object.  For example,
25
 
 
26
 
    Object "bucket" ...
27
 
    Object -> "starfish" ...
28
 
    Object -> "oyster" ...
29
 
    Object -> -> "pearl" ...
30
 
    Object -> "sand" ...
31
 
 
32
 
(where the bulk of the definitions are here abbreviated to "..."), sets
33
 
up the tree structure
34
 
 
35
 
           "bucket"
36
 
              !
37
 
          "starfish" --> "oyster" --> "sand"
38
 
                            !
39
 
                         "pearl"
40
 
 
41
 
The idea is that if no arrows -> are given in the Object definition,
42
 
then the object has no parent: if one -> is given, then the object is a
43
 
child of the last object to be defined with no arrows; if two are
44
 
given, then it's a child of the last object defined with only one
45
 
arrow; and so on.  (The list of definitions looks a little like the
46
 
tree picture turned on its side.)
47
 
 
48
 
   An object definition consists of a "head" followed by a "body",
49
 
which is itself divided into "segments" (though there the similarity
50
 
with caterpillars ends).  The head takes the form:
51
 
 
52
 
         Object <arrows> <name> "textual name" <parent>
53
 
 
54
 
but all of these four entries are optional.
55
 
 
56
 
  1. The <arrows> are as described above.  Note that if one or more
57
 
     arrows are given, that automatically specifies what object this is
58
 
     the child of, so a <parent> cannot be given as well.
59
 
 
60
 
  2. The <name> is what the object can be called inside the program;
61
 
     it's analogous to a variable name.
62
 
 
63
 
  3. The "textual name" can be given if the object's name ever needs to
64
 
     be printed by the program when it is running.
65
 
 
66
 
  4. The <parent> is an object which this new object is to be a child
67
 
     of.  (This is an alternative to supplying arrows.)
68
 
 
69
 
So much is optional that even the bare directive
70
 
 
71
 
    Object;
72
 
 
73
 
is allowed, though it makes a nameless and featureless object which is
74
 
unlikely to be useful.
75
 
 
76
 
 
77
 
File: inform,  Node: Using the Tree,  Next: Objects with Properties,  Prev: Creating Objects,  Up: Objects
78
 
 
79
 
Statements for objects: move, remove, objectloop
80
 
------------------------------------------------
81
 
 
82
 
   The positions of objects in the tree are by no means fixed: they are
83
 
created in a particular formation but are often shuffled around
84
 
extensively during the program's execution.  (In an adventure game,
85
 
where the objects represent items and rooms, objects are moved in the
86
 
tree whenever the player picks something up or moves around.)  The
87
 
statement
88
 
 
89
 
         move <object> to <object>
90
 
 
91
 
moves the first-named object to become a child of the second-named one.
92
 
All of the first object's own children "move along with it", i.e.,
93
 
remain its own children.  For instance, following the example in *Note
94
 
Object Tree:: above,
95
 
 
96
 
    move Cucumber to Mailbox;
97
 
 
98
 
results in the tree
99
 
 
100
 
    Meadow
101
 
      !
102
 
    Mailbox  ----------->  Player
103
 
      !                      !
104
 
    Cucumber  ->  Note     Sceptre  ->  Torch  ->  Magic Rod
105
 
                                          !
106
 
                                       Battery
107
 
 
108
 
It must be emphasized that move prints nothing on the screen, and indeed
109
 
does nothing at all except to rearrange the tree.  When an object
110
 
becomes the child of another in this way, it always becomes the
111
 
"eldest" child in the family-tree sense; that is, it is the new child()
112
 
of its parent, pushing the previous children over into being its
113
 
siblings.  It is, however, illegal to move an object out of such a
114
 
structure using
115
 
 
116
 
    move Torch to nothing;
117
 
 
118
 
because nothing is not an object as such.  The effect is instead
119
 
achieved with
120
 
 
121
 
    remove Torch;
122
 
 
123
 
which would now result in
124
 
 
125
 
    Meadow                                               Torch
126
 
      !                                                    !
127
 
    Mailbox  ----------->  Player                       Battery
128
 
      !                      !
129
 
    Cucumber  ->  Note     Sceptre  ->  Magic Rod
130
 
 
131
 
So the "object tree" is often fragmented into many little trees.
132
 
 
133
 
Since objects move around a good deal, it's useful to be able to test
134
 
where an object currently is; the condition in is provided for this.
135
 
For example,
136
 
 
137
 
    Cucumber in Mailbox
138
 
 
139
 
is true if and only if the Cucumber is one of the direct children of
140
 
the Mailbox.  (Cucumber in Mailbox is true, but Cucumber in Meadow is
141
 
false.)  Note that
142
 
 
143
 
    X in Y
144
 
 
145
 
is only an abbreviation for
146
 
 
147
 
    parent(X) == Y
148
 
 
149
 
but it's worth having since it occurs so often.
150
 
 
151
 
The one loop statement missed out in *Note Routines:: was objectloop.
152
 
 
153
 
         objectloop(<variable-name>) <statement>
154
 
 
155
 
runs through the <statement> once for each object in the tree, putting
156
 
each object in turn into the variable.  For example,
157
 
 
158
 
    objectloop(x) print (name) x, "^";
159
 
 
160
 
prints out a list of the textual names of every object in the tree.
161
 
(Objects which aren't given any textual names in their descriptions
162
 
come out as "?".) More powerfully, any condition can be written in the
163
 
brackets, as long as it begins with a variable name.
164
 
 
165
 
    objectloop(x in Mailbox) print (name) x, "^";
166
 
 
167
 
prints the names only of those objects which are direct children of the
168
 
Mailbox object.
169
 
 
170
 
 
171
 
File: inform,  Node: Objects with Properties,  Next: Private Properties,  Prev: Using the Tree,  Up: Objects
172
 
 
173
 
Creating objects 2: with properties
174
 
-----------------------------------
175
 
 
176
 
   So far Objects are just tokens with names attached which can be
177
 
shuffled around in a tree.  They become interesting when data and
178
 
routines are attached to them, and this is what the body of an object
179
 
definition is for.
180
 
 
181
 
   The body contains up to four segments, which can occur in any order;
182
 
each of the four is optional.  The segments are called
183
 
 
184
 
    with    has    class    private
185
 
 
186
 
class will be left until later.  The most important segment is with,
187
 
which specifies things to be attached to the object.  For example,
188
 
 
189
 
    Object magpie "black-striped bird"
190
 
      with wingspan, worms_eaten;
191
 
 
192
 
attaches two variables to the bird, one called wingspan, the other
193
 
called worms_eaten.  Notice that when more than one variable is given,
194
 
commas are used to separate them: and the object definition as a whole
195
 
is ended by a semicolon, as always.  The values of the magpie's
196
 
variables are referred to in the rest of the program as
197
 
 
198
 
    magpie.wingspan
199
 
    magpie.worms_eaten
200
 
 
201
 
which can be used exactly the way normal (global) variables are used.
202
 
Note that the object has to be named along with the variable, since
203
 
 
204
 
    crested_glebe.wingspan
205
 
    magpie.wingspan
206
 
 
207
 
are different variables.
208
 
 
209
 
   Variables which are attached to objects in this way are called
210
 
"properties".  More precisely, the name wingspan is said to be a
211
 
property, and is said to be "provided" by both the magpie and
212
 
crested_glebe objects.
213
 
 
214
 
   The presence of a property can be tested using the provides
215
 
condition.  For example,
216
 
 
217
 
    objectloop (x provides wingspan) ...
218
 
 
219
 
executes the code ... for each object x in the game which is defined
220
 
with a wingspan property.
221
 
 
222
 
!! Although the provision of a property can be tested, it cannot be
223
 
changed while the program is running.  The value of magpie.wingspan may
224
 
change, but not the fact that the magpie has a wingspan.
225
 
 
226
 
When the above magpie definition is made, the initial values of
227
 
 
228
 
    magpie.wingspan
229
 
    magpie.worms_eaten
230
 
 
231
 
are both 0.  To create the magpie with a given wingspan, we have to
232
 
specify an initial value: we do this by giving it after the name, e.g.
233
 
 
234
 
    Object magpie "black-striped bird"
235
 
      with wingspan 5, worms_eaten;
236
 
 
237
 
and now the program begins with magpie.wingspan equal to 5, and
238
 
magpie.worms_eaten still equal to 0.  (For consistency perhaps there
239
 
should be an equals sign before the 5, but if this were the syntax then
240
 
Inform programs would be horribly full of equals signs.)
241
 
 
242
 
!! Properties can be arrays instead of global variables.  If two or more
243
 
consecutive values are given for the same property, it becomes an
244
 
array.  Thus,
245
 
 
246
 
    Object magpie "black-striped bird"
247
 
      with name "magpie" "bird" "black-striped" "black" "striped",
248
 
           wingspan 5, worms_eaten;
249
 
 
250
 
magpie.name is not a global variable (and cannot be treated as such: it
251
 
doesn't make sense to add 1 to it), it is an --> array.  This must be
252
 
accessed using two special operators, .& and .#.
253
 
 
254
 
    magpie.&name
255
 
 
256
 
means "the array which is held in magpie's name property", so that the
257
 
actual name values are in the entries
258
 
 
259
 
    magpie.&name-->0
260
 
    magpie.&name-->1
261
 
       ...
262
 
    magpie.&name-->4
263
 
 
264
 
The size of this array can be discovered with
265
 
 
266
 
    magpie.#name
267
 
 
268
 
which evaluates to the twice the number of entries, in this case, to 10.
269
 
(Twice the number of entries because it is actually the number of byte
270
 
array, ->, entries: byte arrays take only half as much storage as word
271
 
arrays.)
272
 
 
273
 
!! name is actually a special property created by Inform.  It has the
274
 
unique distinction that textual values in double-quotes (like the five
275
 
words given in magpie.name above) are entered into the game's
276
 
dictionary, and not treated as ordinary strings.  (Normally one would
277
 
use single-quotes for this.  The rule here is anomalous and goes back
278
 
to the misty origins of Inform 1.) If you prefer a consistent style,
279
 
using single quotes:
280
 
 
281
 
    Object magpie "black-striped bird"
282
 
      with name 'magpie' 'bird' 'black-striped' 'black' 'striped',
283
 
           wingspan 5, worms_eaten;
284
 
 
285
 
works equally well (except that single-character names like "X" then
286
 
have to be written #n$X).
287
 
 
288
 
Finally, properties can also be routines.  In the definition
289
 
 
290
 
    Object magpie "black-striped bird"
291
 
      with name "magpie" "bird" "black-striped" "black" "striped",
292
 
           wingspan 5,
293
 
           flying_strength
294
 
           [;  return magpie.wingspan + magpie.worms_eaten;
295
 
           ],
296
 
           worms_eaten;
297
 
 
298
 
magpie.flying_strength is neither a variable nor an array, but a
299
 
routine, given in square brackets as usual.  (Note that the Object
300
 
directive continues where it left off after the routine-end marker, ].)
301
 
Routines which are written in as property values are called "embedded"
302
 
and are mainly used to receive messages (as we shall see).
303
 
 
304
 
!!!! Embedded routines are unlike ordinary ones in two ways:
305
 
  1. An embedded routine has no name of its own, since it is referred to
306
 
     as a property such as magpie.flying_strength instead.
307
 
 
308
 
  2. If execution reaches the ] end-marker of an embedded routine, then
309
 
     it returns false, not true (as a non-embedded routine would).  The
310
 
     reason for this will only become clear in Chapter III when before
311
 
     and after rules are discussed.
312
 
 
313
 
 
314
 
File: inform,  Node: Private Properties,  Next: Using Attributes,  Prev: Objects with Properties,  Up: Objects
315
 
 
316
 
private properties and encapsulation
317
 
------------------------------------
318
 
 
319
 
!!  An optional system is provided for "encapsulating" certain
320
 
properties so that only the object itself has access to them.  These
321
 
are defined by giving them in a segment of the object declaration
322
 
called private.  For instance,
323
 
 
324
 
    Object sentry "sentry"
325
 
      private pass_number 16339,
326
 
      with    challenge
327
 
              [ attempt;
328
 
                  if (attempt == sentry.pass_number)
329
 
                      "Approach, friend!";
330
 
                  "Stand off, stranger.";
331
 
              ];
332
 
 
333
 
makes the sentry provide two properties: challenge, which is public,
334
 
and pass_number, which can be used only by the sentry's own embedded
335
 
routines.
336
 
 
337
 
!!!! This makes the provides condition slightly more interesting than it
338
 
appeared in the previous section.  The answer to the question of whether
339
 
or not
340
 
 
341
 
    sentry provides pass_number
342
 
 
343
 
depends on who's asking: this condition is true if it is tested in one
344
 
of the sentry's own routines, and otherwise false.  A private property
345
 
is so well hidden that nobody else can even know whether or not it
346
 
exists.
347
 
 
348
 
 
349
 
File: inform,  Node: Using Attributes,  Next: Classes and Inheritance,  Prev: Private Properties,  Up: Objects
350
 
 
351
 
Attributes, give and has
352
 
------------------------
353
 
 
354
 
   In addition to properties, objects have flag variables attached.
355
 
(Recall that flags are variables which are either true or false: the
356
 
flag is either flying, or not.)  However, these are provided in a way
357
 
which is quite different.  Unlike property names, attribute names have
358
 
to be declared before use with a directive like:
359
 
 
360
 
    Attribute tedious;
361
 
 
362
 
Once this declaration is made, every object in the tree has a tedious
363
 
flag attached, which is either true or false at any given time.  The
364
 
state can be tested by the has condition:
365
 
 
366
 
    if (magpie has tedious) ...
367
 
 
368
 
tests whether the magpie's tedious flag is currently set, or not.
369
 
 
370
 
   The magpie can be created already having attributes using the has
371
 
segment in its declaration:
372
 
 
373
 
    Object magpie "black-striped bird"
374
 
      with wingspan, worms_eaten
375
 
      has  tedious;
376
 
 
377
 
The has segment contains a list of attributes (with no commas in
378
 
between) which should be initially set.  In addition, an attribute can
379
 
have a tilde ~ in front, indicating "this is definitely not held".
380
 
This is usually what would have happened anyway, but class inheritance
381
 
(see below) disturbs this.
382
 
 
383
 
   Finally, the state of such a flag is changed in the running of the
384
 
program using the give statement:
385
 
 
386
 
    give magpie tedious;
387
 
 
388
 
sets the magpie's tedious attribute, and
389
 
 
390
 
    give magpie ~tedious;
391
 
 
392
 
clears it again.  The give statement can take a list of attributes, too:
393
 
 
394
 
    give door ~locked open;
395
 
 
396
 
for example, meaning "take away locked and add on open".
397
 
 
398
 
 
399
 
File: inform,  Node: Classes and Inheritance,  Next: Messages,  Prev: Using Attributes,  Up: Objects
400
 
 
401
 
Classes and inheritance
402
 
-----------------------
403
 
 
404
 
   Having covered routines and strings in *Note Routines::, and Objects
405
 
above, the fourth and final metaclass to discuss is that of "classes".
406
 
A class is a kind of prototype object from which other objects are
407
 
copied.  These other objects are sometimes called "instances" or
408
 
"members" of the class, and are said to "inherit from" it.
409
 
 
410
 
   For example, clearly all birds ought to have wingspans, and the
411
 
property
412
 
 
413
 
           flying_strength
414
 
           [;  return magpie.wingspan + magpie.worms_eaten;
415
 
           ],
416
 
 
417
 
(attached to the magpie in the example above) is using a formula which
418
 
should work for any bird.  We might achieve this by using directives as
419
 
follows:
420
 
 
421
 
    Class Bird
422
 
      with wingspan 7,
423
 
           flying_strength
424
 
           [;  return self.wingspan + self.worms_eaten;
425
 
           ],
426
 
           worms_eaten;
427
 
 
428
 
    Bird   "magpie"
429
 
      with wingspan 5;
430
 
    Bird   "crested glebe";
431
 
    Bird   "Great Auk"
432
 
      with wingspan 15;
433
 
    Bird   "early bird"
434
 
      with worms_eaten 1;
435
 
 
436
 
   The first definition sets up a new class called Bird.  Every example
437
 
of a Bird now automatically provides wingspan, a flying_strength
438
 
routine and a count of worms_eaten.  Note that the four actual birds
439
 
are created using the Bird class-name instead of the usual plain Object
440
 
directive, but this is only a convenient short form for definitions
441
 
such as:
442
 
 
443
 
    Object "magpie"
444
 
      with wingspan 5
445
 
     class Bird;
446
 
 
447
 
where class is the last of the four object definition segments.  It's
448
 
just a list of classes which the object has to inherit from.
449
 
 
450
 
   The Bird routine for working out flying_strength has to be written
451
 
in such a way that it can apply to any bird.  It has to say "the flying
452
 
strength of any bird is equal to its wingspan plus the number of worms
453
 
it has eaten".  To do this, it has used the special value self, which
454
 
means "whatever object is being considered at the moment".  More of
455
 
this in the next section.
456
 
 
457
 
   Note also that the Bird with specifies a wingspan of 7.  This is the
458
 
value which its members will inherit, unless their own definitions
459
 
over-ride this, as the magpie and great Auk objects do.  Thus the
460
 
initial position is:
461
 
 
462
 
    Bird            Value of wingspan    Value of worms_eaten
463
 
    magpie                5                       0
464
 
    crested glebe         7                       0
465
 
    Great Auk             15                      0
466
 
    early bird            7                       1
467
 
 
468
 
!!!! In rare cases, clashes between what a class says and what the
469
 
object says are resolved differently: see *Note Messages and Classes::.
470
 
 
471
 
Inform has "multiple inheritance", which means that any object can
472
 
inherit from any number of classes.  Thus, an object has no single
473
 
class; rather, it can be a member of several classes at once.
474
 
 
475
 
   Every object is a member of at least one class, because the four
476
 
"metaclasses" Routine, String, Object and Class are themselves classes.
477
 
(Uniquely, Class is a member of itself.)  The magpie above is a member
478
 
of both Bird and Object.
479
 
 
480
 
   To complicate things further, classes can themselves inherit from
481
 
other classes:
482
 
 
483
 
    Class BirdOfPrey
484
 
     class Bird
485
 
     with  wingspan 15,
486
 
           people_eaten;
487
 
 
488
 
    BirdOfPrey kestrel;
489
 
 
490
 
   makes kestrel a member of both BirdOfPrey and of Bird.  Informally,
491
 
BirdOfPrey is called a "subclass" of Bird.
492
 
 
493
 
   Given all this, it's impossible to have a function called class,
494
 
analogous to metaclass, to say what class something belongs to.
495
 
Instead, there is a condition called ofclass:
496
 
 
497
 
    kestrel ofclass Class
498
 
 
499
 
is false, while
500
 
 
501
 
    kestrel ofclass BirdOfPrey
502
 
    kestrel ofclass Bird
503
 
    kestrel ofclass Object
504
 
    "Canterbury" ofclass String
505
 
 
506
 
are all true.  This condition is especially handy for use with
507
 
objectloop:
508
 
 
509
 
    objectloop (x ofclass Bird) move x to Aviary;
510
 
 
511
 
moves all the birds to the Aviary.
512
 
 
513
 
 
514
 
File: inform,  Node: Messages,  Next: Access to Superclass Values,  Prev: Classes and Inheritance,  Up: Objects
515
 
 
516
 
Messages
517
 
--------
518
 
 
519
 
   That completes the story of how to create objects, and it's time to
520
 
begin communicating with them by means of messages.  Every message has
521
 
a sender, a receiver and some parameter values attached, and it always
522
 
produces a reply (which is just a single value).  For instance,
523
 
 
524
 
    x = lamp.addoil(5, 80);
525
 
 
526
 
sends the message addoil with parameters 5 and 80 to the object lamp,
527
 
and puts the reply value into x.  Just as properties like
528
 
magpie.wingspan are variables attached to objects, so messages are
529
 
received by routines attached to objects, and message-sending is very
530
 
like making an ordinary Inform function call.  The "reply" is what was
531
 
called the return value in *Note Routines::, and the "parameters" used
532
 
to be called function call arguments.  But slightly more is involved,
533
 
as will become apparent.
534
 
 
535
 
What does the lamp object do to respond to this message?  First of all,
536
 
it must do something.  If the programmer hasn't specified an addoil
537
 
routine for the lamp, then an error message will be printed out when
538
 
the program is run, along the lines of
539
 
 
540
 
    *** The object "lamp" does not provide the property "addoil" ***
541
 
 
542
 
Not only does lamp.addoil have to exist, but it has to hold one of the
543
 
four kinds of object, or else nothing.  What happens next depends on
544
 
the metaclass of lamp.addoil:
545
 
 
546
 
        metaclass What happens:                The reply is:
547
 
        ========= ============================ =========================
548
 
 
549
 
        Routine   the routine is called with   the routine's return value
550
 
                  the given parameters
551
 
        String    the string is printed,       true
552
 
                  followed by a new-line
553
 
        Object    nothing                      the object
554
 
        Class     nothing                      the class
555
 
        nothing   nothing                      false, or 0, or nothing
556
 
                                               (all different ways of
557
 
                                                   writing 0)
558
 
 
559
 
!! If lamp.addoil is a list rather than a single value then the first
560
 
entry is the one looked at, and the rest are ignored.
561
 
 
562
 
For example,
563
 
 
564
 
    print kestrel.flying_strength();
565
 
 
566
 
will print out 15, by calling the flying_strength routine provided by
567
 
the kestrel (the same one it inherited from Bird), which adds its
568
 
wingspan of 15 to the number of worms it has so far eaten (none), and
569
 
then returns 15.  (You can see all the messages being sent in a game as
570
 
it runs with the debugging verb "messages": see *Note Debugging:: for
571
 
details.)
572
 
 
573
 
!! For examples of all the other kinds of receiving property, here is
574
 
roughly what happens when the Inform library tries to move the player
575
 
northeast from the current room (the location) in an adventure game:
576
 
 
577
 
    x = location.ne_to();
578
 
    if (x == nothing) "You can't go that way.";
579
 
    if (x ofclass Object) move player to x;
580
 
 
581
 
This allows directions to be given with some flexibility in properties
582
 
like ne_to and so on:
583
 
 
584
 
    Object Octagonal_Room "Octagonal Room"
585
 
      with ...
586
 
           ne_to "The north-east doorway is barred by an invisible wall!",
587
 
           w_to  Courtyard,
588
 
           e_to
589
 
           [;  if (Amulet has worn)
590
 
               {   print "A section of the eastern wall suddenly parts before
591
 
                          you, allowing you into...^";
592
 
                   return HiddenShrine;
593
 
               }
594
 
           ],
595
 
           s_to
596
 
           [;  if (random(5) ~= 1) return Gateway;
597
 
               print "The floor unexpectedly gives way, dropping you through
598
 
                      an open hole in the plaster...^";
599
 
               return random(Maze1, Maze2, Maze3, Maze4);
600
 
           ];
601
 
 
602
 
   Two special variables help with the writing of message routines:
603
 
self and sender.  self always has as value the Object which is
604
 
receiving the message, while sender has as value the Object which sent
605
 
it, or nothing if it wasn't sent from Object (but from some
606
 
free-standing routine).  For example,
607
 
 
608
 
    pass_number
609
 
    [;  if (~~(sender ofclass CIA_Operative))
610
 
            "Sorry, you aren't entitled to know that.";
611
 
        return 16339;
612
 
    ];
613
 
 
614
 
 
615
 
File: inform,  Node: Access to Superclass Values,  Next: Philosophy,  Prev: Messages,  Up: Objects
616
 
 
617
 
Access to superclass values
618
 
---------------------------
619
 
 
620
 
!! A fairly common situation in Inform coding is that one has a general
621
 
class of objects, say Treasure, and wants to create an instance of this
622
 
class which behaves slightly differently.  For example, we might have
623
 
 
624
 
    Class  Treasure
625
 
      with deposit
626
 
           [;  if (self provides deposit_points)
627
 
                   score = score + self.deposit_points;
628
 
               else score = score + 5;
629
 
               "You feel a sense of increased esteem and worth.";
630
 
           ];
631
 
 
632
 
and we want to create an instance called Bat_Idol which (say) flutters
633
 
away, resisting deposition, but only if the room is dark:
634
 
 
635
 
    Treasure Bat_Idol "jewelled bat idol"
636
 
      with deposit
637
 
           [;  if (location == thedark)
638
 
               {   remove self;
639
 
                   "There is a clinking, fluttering sound!";
640
 
               }
641
 
               ...
642
 
           ];
643
 
 
644
 
In place of ..., we have to copy out all of the previous code about
645
 
depositing treasures.  This is clumsy: what we really want is a way of
646
 
sending the deposit message to Bat_Idol but "as if it had not changed
647
 
the value of deposit it inherited from Treasure".  We achieve this with
648
 
the so-called superclass operator, ::.  (The term "superclass" is
649
 
borrowed from the Smalltalk-80 system, where it is more narrowly
650
 
defined.)  Thus, in place of ..., we could simply write:
651
 
 
652
 
    self.Treasure::deposit();
653
 
 
654
 
to send itself the deposit message again, but this time diverted to the
655
 
property as provided by Treasure.
656
 
 
657
 
   The :: operator works on all property values, not just for message
658
 
sending.  In general,
659
 
 
660
 
    object.class::property
661
 
 
662
 
evaluates to the value of the given property which the class would
663
 
normally pass on (or gives an error if the class doesn't provide that
664
 
property or if the object isn't a member of that class).  Note that ::
665
 
exists as an operator in its own right, so it is perfectly legal to
666
 
write, for example,
667
 
 
668
 
    x = Treasure::deposit; Bat_Idol.x();
669
 
 
670
 
To continue the avian theme, BirdOfPrey might have its own
671
 
flying_strength routine:
672
 
 
673
 
           flying_strength
674
 
           [;  return self.Bird::flying_strength() + self.people_eaten;
675
 
           ],
676
 
 
677
 
reflecting the idea that, unlike other birds, these can gain strength by
678
 
eating people.
679
 
 
680
 
 
681
 
File: inform,  Node: Philosophy,  Next: Sending Messages,  Prev: Access to Superclass Values,  Up: Objects
682
 
 
683
 
Philosophy
684
 
----------
685
 
 
686
 
!!!! This section is best skipped until the reader feels entirely happy
687
 
with the rest of Chapter I.  It is aimed mainly at those worried about
688
 
whether the ideas behind the apparently complicated system of classes
689
 
and objects are sound.  (As Stephen Fry once put it, "Socialism is all
690
 
very well in practice, but does it work in theory?")  We begin with two
691
 
definitions:
692
 
 
693
 
`object'
694
 
     a member of the program's object tree, or a routine in the
695
 
     program, or a literal string in the program.  (Routines and
696
 
     strings can't, of course, be moved around in the object tree, but
697
 
     the tests ofclass and provides can be applied to them, and they
698
 
     can be sent messages.)  Objects are part of the compiled program
699
 
     produced by Inform.
700
 
 
701
 
`class'
702
 
     an abstract name for a set of objects in the game, which may have
703
 
     associated with it a set of characteristics shared by its objects.
704
 
     Classes themselves are frequently described by text in the
705
 
     program's source code, but are not part of the compiled program
706
 
     produced by Inform.
707
 
 
708
 
Here are the full rules:
709
 
  1. Compiled programs are composed of objects, which may have variables
710
 
     attached called "properties".
711
 
 
712
 
  2. Source code contains definitions of both objects and classes.
713
 
 
714
 
  3. Any given object in the program either is, or is not, a member of
715
 
     any given class.
716
 
 
717
 
  4. For every object definition in the source code, an object is made
718
 
     in the final program.  The definition specifies which classes this
719
 
     object is a member of.
720
 
 
721
 
  5. If an object X is a member of class C, then X "inherits" property
722
 
     values as given in the class definition of C.
723
 
 
724
 
     The details of how inheritance takes place are omitted here.  But
725
 
     note that one of the things which can be inherited from class C is
726
 
     being a member of some other class, D.
727
 
 
728
 
  6. For every class definition, an object is made in the final program
729
 
     to represent it, called its "class-object".
730
 
 
731
 
     For example, suppose we have a class definition like:
732
 
 
733
 
         Class Dwarf
734
 
          with beard_colour;
735
 
 
736
 
     The class Dwarf will generate a class-object in the final program,
737
 
     also called Dwarf.  This class-object exists in order to receive
738
 
     messages like create and destroy and, more philosophically, in
739
 
     order to represent the concept of "dwarfness" within the simulated
740
 
     world.
741
 
 
742
 
     It is important to remember that the class-object of a class is
743
 
     not normally a member of that class.  The concept of dwarfness is
744
 
     not itself a dwarf: the condition Dwarf ofclass Dwarf is false.
745
 
     Individual dwarves provide a property called beard_colour, but the
746
 
     class-object of Dwarf does not: the concept of dwarfness has no
747
 
     single beard colour.
748
 
 
749
 
  7. Classes which are automatically defined by Inform are called
750
 
     "metaclasses".  There are four of these: Class, Object, Routine
751
 
     and String.
752
 
 
753
 
     It follows by rule (6) that every Inform program contains the
754
 
     class-objects of these four, also called Class, Object, Routine
755
 
     and String.
756
 
 
757
 
  8. Every object is a member of one, and only one, metaclass:
758
 
       1. The class-objects are members of Class, and no other class.
759
 
 
760
 
       2. Routines in the program (including those given as property
761
 
          values) are members of Routine and no other class.
762
 
 
763
 
       3. Static strings in the program (including those given as
764
 
          property values) are members of String, and of no other class.
765
 
 
766
 
       4. The objects defined in the source code are members of Object,
767
 
          and possibly also of other classes defined in the source code.
768
 
 
769
 
     It follows from (8.1) that Class is the unique class whose
770
 
     class-object is one of its own members: the condition Class
771
 
     ofclass Class is true, whereas X ofclass X is false for every
772
 
     other class X.
773
 
 
774
 
     There is one other unusual feature of metaclasses, and it is a
775
 
     rule provided for pragmatic reasons (see below) even though it is
776
 
     not very elegant:
777
 
 
778
 
  9. Contrary to rules (5) and (8.1), the class-objects of the four
779
 
     metaclasses do not inherit from Class.
780
 
 
781
 
This concludes the list of rules.  To see what they entail, one needs to
782
 
know the definitions of the four metaclasses.  These definitions are
783
 
never written out in any textual form inside Inform, as it happens, but
784
 
here are definitions equivalent to what actually does happen.  (There
785
 
is no such directive as Metaclass: none is needed, since only Inform
786
 
itself can define metaclasses, but the definitions here pretend that
787
 
there is.)
788
 
 
789
 
    Metaclass Object;
790
 
 
791
 
In other words, this is a class from which nothing is inherited.  So the
792
 
ordinary objects described in the source code only have the properties
793
 
which the source code says they have.
794
 
 
795
 
    Metaclass Class
796
 
    with create    [; ... ],
797
 
         recreate  [ instance; ... ],
798
 
         destroy   [ instance; ... ],
799
 
         copy      [ instance1 instance2; ... ],
800
 
         remaining [; ... ];
801
 
 
802
 
So class-objects respond only to these five messages, which are
803
 
described in detail in the next section, and provide no other
804
 
properties: *except* that by rule (9), the class-objects Class, Object,
805
 
Routine and String provide no properties at all.  The point is that
806
 
these five messages are concerned with object creation and deletion at
807
 
run time.  But Inform is a compiler and not, like Smalltalk-80 or other
808
 
highly object-oriented languages, an interpreter.  We cannot create the
809
 
program while it is actually running, and this is what it would mean to
810
 
send requests for creation or deletion to Class, Object, Routine or
811
 
String.  (We could write the above routines to allow the requests to be
812
 
made, but to print out some error if they ever are: but it is more
813
 
efficient to have rule (9) instead.)
814
 
 
815
 
    Metaclass Routine
816
 
    with call      [ parameters...; ... ];
817
 
 
818
 
Routines therefore provide only call.  See the next section for how to
819
 
use this.
820
 
 
821
 
    Metaclass String
822
 
    with print     [; print_ret (string) self; ],
823
 
         print_to_array [ array; ... ];
824
 
 
825
 
Strings therefore provide only print and print_to_array.  See the next
826
 
section for how to use these.
827
 
 
828
 
To demonstrate this, here is an Inform code representation of what
829
 
happens when the message
830
 
 
831
 
     O.M(p1, p2, ...)
832
 
 
833
 
is sent.
834
 
 
835
 
     if (~~(O provides M)) "Error: O doesn't provide M";
836
 
     P = O.M;
837
 
     switch(metaclass(P))
838
 
     {   nothing, Object, Class: return P;
839
 
         Routine:                return P.call(p1, p2, ...);
840
 
         String:                 return P.print();
841
 
     }
842
 
 
843
 
(The messages call and print are actually implemented by hand, so this
844
 
is not actually a circular definition.  Also, this is simplified to
845
 
remove details of what happens if P is an array.)
846
 
 
847
 
 
848
 
File: inform,  Node: Sending Messages,  Next: Dynamic Objects,  Prev: Philosophy,  Up: Objects
849
 
 
850
 
Sending messages to routines, strings or classes
851
 
------------------------------------------------
852
 
 
853
 
!! In the examples so far, messages have only been sent to proper
854
 
Objects.  But it's a logical possibility to send messages to objects of
855
 
the other three metaclasses too: the question is whether they are able
856
 
to receive any.  The answer is yes, because Inform provides 8
857
 
properties for such objects, as follows.
858
 
 
859
 
   The only thing you can do with a Routine is to call it.  Thus, if
860
 
Explore is the name of a routine, then
861
 
 
862
 
    Explore.call(2, 4);      and      Explore(2, 4);
863
 
 
864
 
are equivalent expressions.  The message call(2,4) means "run this
865
 
routine with parameters (2,4)".  This is not quite redundant, because
866
 
it can be used more flexibly than ordinary function calls:
867
 
 
868
 
    x = Explore; x.call(2, 4);
869
 
 
870
 
The call message replies with the routine's return value.
871
 
 
872
 
   Two different messages can be sent to a String.  The first is print,
873
 
which is provided because it logically ought to be, rather than because
874
 
it is useful.  So, for example,
875
 
 
876
 
    ("You can see an advancing tide of bison!").print();
877
 
 
878
 
prints out the string, followed by a new-line; the print message replies
879
 
true, or 1.
880
 
 
881
 
!!!! print_to_array is more useful.  It copies out the text of the
882
 
string into entries 2, 3, 4, ... of the supplied byte array, and writes
883
 
the number of characters as a word into entries 0 and 1.  That is, if A
884
 
has been declared as a suitably large array,
885
 
 
886
 
    ("A rose is a rose is a rose").print_to_array(A);
887
 
 
888
 
will cause the text of the string to be copied into the entries
889
 
 
890
 
    A->2, A->3, ..., A->27
891
 
 
892
 
with the value 26 written into
893
 
 
894
 
    A-->0
895
 
 
896
 
And the reply value of the message is also 26, for convenience.
897
 
 
898
 
   Five different messages can be sent to objects of metaclass Class,
899
 
i.e., to classes, and these are detailed in the next section.  (But an
900
 
exception to this is that no messages at all can be sent to the four
901
 
metaclasses Class, Object, Routine and String.)
902
 
 
903
 
 
904
 
File: inform,  Node: Dynamic Objects,  Next: Common vs Individual,  Prev: Sending Messages,  Up: Objects
905
 
 
906
 
Creating and deleting objects
907
 
-----------------------------
908
 
 
909
 
   A vexed problem in all object-oriented systems is that it is often
910
 
elegant to grow data structures organically, simply conjuring new
911
 
objects out of mid-air and attaching them to the structure already
912
 
built.  The problem is that since resources cannot be infinite, there
913
 
will come a point where no new objects can be conjured up.  The program
914
 
must be written so that it can cope with this, and this can present the
915
 
programmer with some difficulty, since the conditions that will prevail
916
 
when the program is being run may be hard to predict.
917
 
 
918
 
   In an adventure-game setting, object creation is useful for
919
 
something like a beach full of stones: if the player wants to pick up
920
 
more and more stones, the game needs to create a new object for each
921
 
stone brought into play.
922
 
 
923
 
   Inform allows object creation, but it insists that the programmer
924
 
must specify in advance what the maximum resources ever needed will be:
925
 
for example, the maximum number of stones which can ever be in play.
926
 
Although this is a nuisance, the reward is that the resulting program
927
 
is guaranteed to work correctly on every machine running it (or else to
928
 
fail in the same way on every machine running it).
929
 
 
930
 
   The model is this.  When a class is defined, a number N is
931
 
specified, which is the maximum number of created instances of the
932
 
class which the programmer will ever need at once.  When the program is
933
 
running, "instances" can be created (up to this limit); or deleted.
934
 
One can imagine the class having a stock of instances, so that creation
935
 
consists of giving out one of the stock-pile and deletion consists of
936
 
taking one back.
937
 
 
938
 
   Classes can receive the following five messages:
939
 
 
940
 
remaining()
941
 
 
942
 
What is the current value of N?  That is, how many more instances can
943
 
be created?
944
 
 
945
 
create()
946
 
 
947
 
Replies with a newly created instance, or with nothing if no more can
948
 
be created.
949
 
 
950
 
destroy(I)
951
 
 
952
 
Destroys the instance I, which must previously have been created.
953
 
 
954
 
recreate(I)
955
 
 
956
 
Re-initialises the instance I, as if it had been destroyed and then
957
 
created again.
958
 
 
959
 
copy(I, J)
960
 
 
961
 
Copies I to be equal to J, where both have to be instances of the class.
962
 
 
963
 
!! Note that recreate and copy can be sent for any instances, not just
964
 
instances which have previously been created.  For example,
965
 
 
966
 
    Plant.copy(Gilded_Branch, Poison_Ivy)
967
 
 
968
 
copies over all the Plant properties and attributes from Poison_Ivy to
969
 
Gilded_Branch, but leaves all the rest alone.  Likewise,
970
 
 
971
 
    Treasure.recreate(Gilded_Branch)
972
 
 
973
 
only resets the properties to do with Treasure, leaving the Plant
974
 
properties alone.
975
 
 
976
 
   Unless the definition of a class C is made in a special way,
977
 
C.remaining() will always reply 0, C.destroy() will cause an error and
978
 
C.create() will be refused.  This is because the magic number N for a
979
 
class is normally 0.
980
 
 
981
 
   The "special way" is to give N in brackets after the class name.  For
982
 
example, if the class definition for Leaf begins:
983
 
 
984
 
    Class Leaf(100) ...
985
 
 
986
 
then initially Leaf.remaining() will reply 100, and the first 100
987
 
create() messages will certainly be successful.  Others will only
988
 
succeed if leaves have been destroyed in the mean time.  In all other
989
 
respects Leaf is an ordinary class.
990
 
 
991
 
!! Object creation and destruction may need to be more sophisticated
992
 
than this.  For example, we might have a data structure in which every
993
 
object of class A is connected in some way with four objects of class
994
 
B.  When a new A is created, four new Bs need to be created for it; and
995
 
when an A is destroyed, its four Bs need to be destroyed.  In an
996
 
adventure game setting, we might imagine that every Dwarf who is
997
 
created has to carry an Axe of his own.
998
 
 
999
 
   When an object has been created (or recreated), but before it has
1000
 
been "given out" to the program, a create message is sent to it (if it
1001
 
provides create).  This gives the object a chance to set itself up
1002
 
sensibly.  Similarly, when an object is about to be destroyed, but
1003
 
before it actually is, a destroy message is sent to it (if it provides
1004
 
destroy).  For example:
1005
 
 
1006
 
    Class Axe(30);
1007
 
    Class Dwarf(7)
1008
 
     with beard_colour,
1009
 
          create
1010
 
          [ x; self.beard_colour = random("black", "red", "white", "grey");
1011
 
 
1012
 
               !  Give this new dwarf an axe, if there are any to spare
1013
 
 
1014
 
               x = Axe.create(); if (x ~= nothing) move x to self;
1015
 
          ],
1016
 
          destroy
1017
 
          [ x;
1018
 
               !  Destroy any axes being carried by this dwarf
1019
 
 
1020
 
               objectloop (x in self && x ofclass Axe) Axe.destroy(x);
1021
 
          ];
1022
 
 
1023
 
 
1024
 
File: inform,  Node: Common vs Individual,  Prev: Dynamic Objects,  Up: Objects
1025
 
 
1026
 
Footnote on common vs. individual properties
1027
 
--------------------------------------------
1028
 
 
1029
 
!!!!  The properties used in the sections above are all examples of
1030
 
"individual properties", which some objects provide and others do not.
1031
 
There are also "common properties" which, because they are inherited
1032
 
from the class Object, are held by every member of Object.  An example
1033
 
is capacity.  The capacity can be read for an ordinary game object
1034
 
(say, a crate) even if it doesn't specify a capacity for itself, and
1035
 
the resulting "default" value will be 100.  However, this is only a
1036
 
very weak form of inheritance -- you can't change the crate's capacity
1037
 
value and the condition crate provides capacity evaluates to false.
1038
 
 
1039
 
   The properties defined by the Inform library, such as capacity, are
1040
 
all common: mainly because common properties are marginally faster to
1041
 
access and marginally cheaper on memory.  Only 62 are available, of
1042
 
which the library uses up 48.  Individual properties, on the other
1043
 
hand, are practically unlimited. It is therefore worth declaring a
1044
 
common property only in those cases where it will be used very often in
1045
 
your program.  You can declare common properties with the directive:
1046
 
 
1047
 
     Property <name>;
1048
 
 
1049
 
which should be made after the inclusion of "Parser" but before first
1050
 
use of the new name.  The class Object will now pass on this property,
1051
 
with value 0, to all its members.  This so-called "default value" can
1052
 
optionally be specified.  For example, the library itself makes the
1053
 
declaration
1054
 
 
1055
 
     Property capacity 100;
1056
 
 
1057
 
which is why all containers in a game which don't specify any particular
1058
 
capacity can hold up to 100 items.
1059
 
 
1060
 
 
1061
 
File: inform,  Node: Using the Compiler,  Next: Fundamentals,  Prev: Programming Language,  Up: Top
1062
 
 
1063
 
Using the Compiler
1064
 
******************
1065
 
 
1066
 
     I was promised a horse, but what I got instead
1067
 
     was a tail, with a horse hung from it almost dead.
1068
 
     
1069
 
     -- Palladas of Alexandria (319?-400?)
1070
 
     -- translated by Tony Harrison (1937-)
1071
 
 
1072
 
* Menu:
1073
 
 
1074
 
* The Language of Inform::      The language of Inform
1075
 
* Compiler Options::            Compiler options and memory settings
1076
 
* Error Messages::              All the Inform error messages
1077
 
 
1078
 
 
1079
 
File: inform,  Node: The Language of Inform,  Next: Compiler Options,  Prev: Using the Compiler,  Up: Using the Compiler
1080
 
 
1081
 
The language of Inform
1082
 
======================
1083
 
 
1084
 
* Menu:
1085
 
 
1086
 
* ICL::                         The Inform Command Language
1087
 
* Controlling Compilation::     Controlling what is compiled
1088
 
* Linking::                     Using the linker
1089
 
 
1090
 
 
1091
 
File: inform,  Node: ICL,  Next: Controlling Compilation,  Prev: The Language of Inform,  Up: The Language of Inform
1092
 
 
1093
 
ICL
1094
 
---
1095
 
 
1096
 
   The Inform compiler is quite configurable: it has a number of
1097
 
settings which can be altered to suit the convenience of the user.
1098
 
Many of these settings are "switches", which usually have just two
1099
 
possible states, off or on.  However, some can be set to a single-digit
1100
 
number.
1101
 
 
1102
 
   The other numerical settings are "memory settings", which control
1103
 
how much of your computer's memory Inform uses while running (too low
1104
 
and it may not be able to compile games of the size you desire; too
1105
 
high and it may choke any other programs in the computer for space).
1106
 
 
1107
 
   Finally, there are "path variables", which contain text and are used
1108
 
to sort out filenames for the files Inform uses or creates.  The usage
1109
 
of these variables varies widely from machine to machine, or rather,
1110
 
from one operating system to another.
1111
 
 
1112
 
   If Inform seems to work adequately for you already, this section can
1113
 
safely be ignored until the day comes to compile a really big project.
1114
 
Times like that call for the ability to conveniently change many
1115
 
settings at once, and a tiny language called "ICL" is provided for you
1116
 
to supply detailed specifications.
1117
 
 
1118
 
On many systems, though not usually the Apple Macintosh, the user sets
1119
 
Inform running by typing a command at the "command line", that is, in
1120
 
response to a prompt printed by the computer.  For example, under RISC
1121
 
OS one would press function key f12 from the desktop and be given the
1122
 
prompt *, to which one might reply
1123
 
 
1124
 
inform ruins
1125
 
 
1126
 
On computers with more doggedly windowed interfaces, there will be a
1127
 
higher-level interface of some kind provided with Inform, which should
1128
 
come with its own brief documentation.
1129
 
 
1130
 
   The usual way to alter switches on the command line is to give a
1131
 
word of options after the inform command, introduced by a minus sign.
1132
 
The switches are all single letters, and by default are mostly off.  For
1133
 
example, the -x switch causes Inform to print a row of hash signs as it
1134
 
compiles:
1135
 
 
1136
 
inform -x shell
1137
 
RISC OS Inform 6.01 (April 25th 1996)
1138
 
::###############################################################
1139
 
 
1140
 
One hash sign is printed for every 100 textual lines of source code
1141
 
compiled.  (On my own machine, an Acorn Risc PC 700, about 10 hashes
1142
 
are printed every second: that is, the compilation speed is about 1000
1143
 
lines per second.) Although -x is provided to indicate that a slow
1144
 
compilation is continuing normally, many designers use it to get a
1145
 
feeling for how large their games are, and it's a morale boost when the
1146
 
row of hashes spills over onto a second screen line.
1147
 
 
1148
 
   Inform has documentation built-in on the subject of switches and
1149
 
other ICL features, which may vary from machine to machine.  Running
1150
 
Inform with no filename will print this "help information".  In
1151
 
addition, -h1 will print details of filenaming conventions in use on
1152
 
your machine, and -h2 will print a list of switches and their settings.
1153
 
 
1154
 
   The full command line syntax is
1155
 
 
1156
 
     inform <ICL commands> <source file> <output file>
1157
 
 
1158
 
where only the <source file> is mandatory.  By default, the full names
1159
 
to give the source and output files are derived in a way suitable for
1160
 
the machine Inform is running on: on a PC, for instance, advent may be
1161
 
understood as asking to compile advent.inf to advent.z5.  This is called
1162
 
"filename translation".  No detailed information on filenaming rules is
1163
 
given here, because it varies so much from machine to machine: see the
1164
 
-h1 on-line documentation.  Note however that a filename can contain
1165
 
spaces if it is written in double-quotes.
1166
 
 
1167
 
One possible ICL command is to give a filename in brackets: e.g.,
1168
 
 
1169
 
     inform -x (skyfall_setup) ...
1170
 
 
1171
 
sets the -x switch, then runs through the text file skyfall_setup
1172
 
executing each line as an ICL command.  As an example, this file might
1173
 
read as follows:
1174
 
 
1175
 
   ! Setup file for "Skyfall"
1176
 
 
1177
 
   -d                   ! Contract double spaces
1178
 
   $max_objects=1000    ! 500 of them snowflakes
1179
 
   (usual_setup)        ! include my favourite settings, too
1180
 
   +module_path=mods    ! keep modules in the "mods" directory
1181
 
 
1182
 
   Note that ICL can include comments after !, just as in Inform.
1183
 
Otherwise, an ICL file has one command per line (with no dividing
1184
 
semicolons), and the possibilities are as follows:
1185
 
 
1186
 
-<switches>
1187
 
 
1188
 
set these switches; or unset any switch preceded by a tilde ~.  (For
1189
 
example, -a~bc sets a, unsets b and sets c.)
1190
 
 
1191
 
$list
1192
 
 
1193
 
list current memory settings
1194
 
 
1195
 
$?<name>
1196
 
 
1197
 
ask for information on what this memory setting is for
1198
 
 
1199
 
$small
1200
 
 
1201
 
set the whole collection of memory settings to suitable levels for a
1202
 
small game
1203
 
 
1204
 
$large
1205
 
 
1206
 
ditto, for a slightly larger game
1207
 
 
1208
 
$huge
1209
 
 
1210
 
ditto, for a reasonably big one
1211
 
 
1212
 
$<name>=<quantity>
1213
 
 
1214
 
alter the named memory setting to the given level
1215
 
 
1216
 
+<name>=<filename>
1217
 
 
1218
 
set the named pathname variable to the given filename, which should be
1219
 
one or more filenames of directories, separated by commas
1220
 
 
1221
 
compile <filename> <filename>
1222
 
 
1223
 
compile the first-named file, containing source code, writing the
1224
 
output program to the (optional) second-named file
1225
 
 
1226
 
(<filename>)
1227
 
 
1228
 
execute this ICL file (files may call each other in this way)
1229
 
 
1230
 
 
1231
 
File: inform,  Node: Controlling Compilation,  Next: Linking,  Prev: ICL,  Up: The Language of Inform
1232
 
 
1233
 
Controlling what is compiled
1234
 
----------------------------
1235
 
 
1236
 
   Several directives instruct Inform to "compile this part next" or
1237
 
"only compile this...".  First,
1238
 
 
1239
 
    Include "filename";
1240
 
 
1241
 
instructs Inform to compile the whole of the source code in the given
1242
 
file, and only carry on compiling from here once that is complete.  It
1243
 
is exactly equivalent to removing the Include directive and replacing it
1244
 
with the whole file "filename".  (The rules for how Inform interprets
1245
 
"filename" vary from machine to machine: run Inform with the -h1 switch
1246
 
for information.)  Note that you can write
1247
 
 
1248
 
    Include ">shortname";
1249
 
 
1250
 
to mean "the file called "shortname" which is in the same directory
1251
 
that the present file came from".  This is convenient if all the files
1252
 
making up the source code of your game are housed together.
1253
 
 
1254
 
!!  Next, there are a number of "conditional compilation" directives.
1255
 
They take the general form of a condition:
1256
 
 
1257
 
    Ifdef <name>;          Is the name defined as having some meaning?
1258
 
    Ifndef <name>;         Is the name undefined?
1259
 
    Iftrue <condition>;    Is this condition true?
1260
 
    Iffalse <condition>;   Is this condition false?
1261
 
 
1262
 
followed by a chunk of Inform and then either
1263
 
 
1264
 
    Ifnot;
1265
 
 
1266
 
and another chunk of Inform, or just
1267
 
 
1268
 
    Endif;
1269
 
 
1270
 
   At this point it is perhaps worth mentioning that (most) directives
1271
 
can also be interspersed with statements in routine declarations,
1272
 
provided they are preceded by a # sign.  For example:
1273
 
 
1274
 
    [ MyRoutine;
1275
 
    #Iftrue MAX_SCORE > 1000;
1276
 
      print "My, what a long game we're in for!^";
1277
 
    #Ifnot;
1278
 
      print "Let's have a quick game, then.^";
1279
 
    #Endif;
1280
 
      PlayTheGame();
1281
 
    ];
1282
 
 
1283
 
which actually only compiles one of the two print statements, according
1284
 
to what the value of the constant MAX_SCORE is.
1285
 
 
1286
 
!!!! Four more arcane directives control conditional compilation.
1287
 
 
1288
 
    Default <name> <value>;
1289
 
 
1290
 
defines <name> as a constant if it wasn't already the name of something:
1291
 
so it's equivalent to the manoeuvre
1292
 
 
1293
 
    Ifndef <name>;
1294
 
    Constant <name> = <value>;
1295
 
    Endif;
1296
 
 
1297
 
Similarly,
1298
 
 
1299
 
    Stub <name> <number>;
1300
 
 
1301
 
defines a routine with this name and number of local variables, if it
1302
 
isn't already the name of something: so it's equivalent to
1303
 
 
1304
 
    Ifndef <name>;
1305
 
    [ <name> x1 x2 ... x<number>;
1306
 
    ];
1307
 
    Endif;
1308
 
 
1309
 
!!!!  Large blocks of code intended to be used in many different games,
1310
 
such as the files which make up the Inform library, should be marked
1311
 
somewhere with the directive
1312
 
 
1313
 
    System_file;
1314
 
 
1315
 
If this is done, it is possible for an outside program including the
1316
 
file to use Replace.  The idea is that a sequence like:
1317
 
 
1318
 
    Replace DoSomething;
1319
 
    ...
1320
 
    Include "SomeLibrary";
1321
 
    ...
1322
 
    [ DoSomething; "Tarantaraa!"; ];
1323
 
 
1324
 
allows a routine DoSomething, which would normally be defined in the
1325
 
Include file "SomeLibrary", to be defined in this file instead.  The
1326
 
definition in the Include file is simply ignored.  In this way, one can
1327
 
override the library routines without actually having to modify the
1328
 
library source code.  To recap, the rule here is that a routine's
1329
 
definition is ignored if both (a) it occurs in a declared "system
1330
 
file", and (b) its name has been given in a Replace directive.
1331
 
 
1332
 
One way to follow what is being compiled is to use the Message
1333
 
directive.  The compiler can be made to print messages at compile time
1334
 
using:
1335
 
 
1336
 
     Message "information"
1337
 
     Message error "error message"
1338
 
     Message fatalerror "fatal error message"
1339
 
     Message warning "warning message"
1340
 
 
1341
 
For example,
1342
 
 
1343
 
    Ifndef VN_1610;
1344
 
    Message fatalerror "This code can only be compiled by Inform 6.1";
1345
 
    Endif;
1346
 
 
1347
 
(By a special rule, the condition VN_1610-is-defined is true if and only
1348
 
if the version number is 6.10 or more; similarly for other four-digit
1349
 
numbers beginning with a 1.)  Informational messages are simply
1350
 
printed: e.g.,
1351
 
 
1352
 
    Message "Library extension by Boris J. Parallelopiped";
1353
 
 
1354
 
just prints out this line (with a carriage return).
1355
 
 
1356
 
 
1357
 
File: inform,  Node: Linking,  Prev: Controlling Compilation,  Up: The Language of Inform
1358
 
 
1359
 
Using the linker
1360
 
----------------
1361
 
 
1362
 
   The process of "linking" is as follows.  A game being compiled
1363
 
(called the "external" program) may Link one or more pre-compiled
1364
 
sections of code called "modules".  Suppose the game Jekyll has a
1365
 
subsection called Hyde.  Then these two methods of making Jekyll are,
1366
 
nearly, equivalent:
1367
 
  1. Putting Include "Hyde"; in the source code for "Jekyll", and
1368
 
     compiling "Jekyll".
1369
 
 
1370
 
  2. Compiling "Hyde" with the -M ("module") switch set, then putting
1371
 
     Link "Hyde"; into the same point in the source code for "Jekyll",
1372
 
     and compiling "Jekyll".
1373
 
 
1374
 
Option (2) is much faster as long as "Hyde" does not change very often,
1375
 
since its ready-compiled module can be left lying around while "Jekyll"
1376
 
is being developed.
1377
 
 
1378
 
   Because "linking the library" is by far the most common use of the
1379
 
linker, this is made simple.  All you have to do is compile your game
1380
 
with the -U switch set, or, equivalently, to begin your source code with
1381
 
 
1382
 
    Constant USE_MODULES;
1383
 
 
1384
 
(This assumes that you already have pre-compiled copies of the two
1385
 
library modules: if not, you'll need to make them with
1386
 
 
1387
 
    inform -M library.parserm
1388
 
    inform -M library.verblibm
1389
 
 
1390
 
(where library.parserm should be replaced with the filename for your
1391
 
copy of the library file "parserm", and likewise for "verblibm").) Note
1392
 
that it is essential not to make any Attribute or Property declarations
1393
 
`before' the Include "Parser" line in the source code, though `after'
1394
 
that point is fine.  (Library 6/2 and later will print an error message
1395
 
if you make this mistake, but under 6/1 it can be a source of
1396
 
mysterious problems.)
1397
 
 
1398
 
!!!! You can also write your own library modules, or indeed subdivide a
1399
 
large game into many modular parts.  But there are certain restrictions
1400
 
to the possibilities.  (Real experts may want to look at the Technical
1401
 
Manual here.)  Here's a brief list of these:
1402
 
 
1403
 
1.  The module must make the same Property and Attribute directives as
1404
 
the main program.  Including the library file "linklpa.h" ("link
1405
 
library properties and attributes") declares the library's stock, so it
1406
 
would be sensible to begin a module with
1407
 
 
1408
 
    Include "linklpa";
1409
 
 
1410
 
and then include a similar file defining all the extra common properties
1411
 
and attributes which are needed by the program (if any).
1412
 
 
1413
 
2.  The module cannot contain grammar (i.e., use Verb or Extend
1414
 
directives) or create fake actions.
1415
 
 
1416
 
3.  The module can only use global variables defined outside the module
1417
 
if they are explicitly declared before use using the Import directive.
1418
 
For example,
1419
 
 
1420
 
    Import global frog;
1421
 
 
1422
 
allows the rest of the module's source code to refer to the variable
1423
 
frog (which must be defined in the outside program).  Note that the
1424
 
Include file "linklv.h" ("link library variables") imports all the
1425
 
library variables, so it would be sensible to include this.
1426
 
 
1427
 
4.  An object in the module can't inherit from a class defined outside
1428
 
the module.  (But an object outside can inherit from a class inside.)
1429
 
 
1430
 
5.  Certain constant values in the module must be known at
1431
 
module-compile-time (and must not, for instance, be a symbol only
1432
 
defined outside the module).  For instance: the size of an array must be
1433
 
known now, not later; the number of duplicate members of a Class; and
1434
 
the quantities being compared in an Iftrue or Iffalse.
1435
 
 
1436
 
6.  The module can't: define the Main routine; use the Stub or Default
1437
 
directives; or define an object whose parent object is not also in the
1438
 
same module.
1439
 
 
1440
 
These restrictions are mild in practice.  As an example, here is a
1441
 
short module to play with:
1442
 
 
1443
 
    Include "linklpa";        ! Make use of the properties, attributes
1444
 
    Include "linklv";         ! and variables from the Library
1445
 
 
1446
 
    [ LitThings x;
1447
 
      objectloop (x has light)
1448
 
          print (The) x, " is currently giving off light.^";
1449
 
    ];
1450
 
 
1451
 
   It should be possible to compile this -M and then to Link it into
1452
 
another game, making the routine LitThings exist in that game.