1 ==============================
2 Heidi: our first Inform game
3 ==============================
7 | *E was an esquire, with pride on his brow;*
8 | *F was a farmer, and followed the plough.*
11 .. image:: /images/picE.png
18 ach of the three games in this guide is created step by step; you'll get
19 most benefit (especially to begin with) if you take an active part, typing
20 in the source code on your computer. Our first game, described in this
21 chapter and the two which follow, tells this sentimental little story:
23 "Heidi lives in a tiny cottage deep in the forest. One sunny day,
24 standing before the cottage, she hears the frenzied tweeting of baby
25 bird; its nest has fallen from the tall tree in the clearing! Heidi
26 puts the bird into the nest, and then climbs the tree to place the nest
29 It's a very simple tale, but even so we'll cover quite a lot of ground
30 before we have a finished Inform game. We'll get there in stages, first
31 making a very rough approximation of the story, and then successively
32 refining the details until it's good enough for an initial attempt (there's
33 time later for more advanced stuff).
35 Creating a basic source file
36 ============================
38 The first task is to create an Inform source file template. Every game
39 that we design will start out like this. Follow these steps:
41 #. Create an ``Inform\Games\Heidi`` folder (maybe by copying ``Inform\Games\MyGame1``).
45 In this guide, we use the PC convention of placing a backslash
46 between folder names. On a Macintosh, use a regular slash:
47 ``Inform/Games/Heidi``.
49 #. In that folder, use your text editor to create this source file
52 .. code-block:: inform6
55 !============================================================================
56 Constant Story "Heidi";
58 "^A simple Inform example
59 ^by Roger Firth and Sonja Kesserich.^";
64 !============================================================================
67 !============================================================================
68 ! Entry point routines
72 !============================================================================
73 ! Standard and extended grammar
77 !============================================================================
79 Soon, we'll explain what this means. For now, just type it all in,
80 paying particular attention to those seven semicolons, and ensuring that
81 the double quotes "..." always come in pairs. The first line beginning
82 with "``!%``" is special, and we'll talk about it in a moment; the
83 remaining exclamation mark lines, on the other hand, are purely
84 decorative; they just make the file's structure a little easier to
87 Ensure the file is named ``Heidi.inf``, rather than ``Heidi.txt`` or
90 Remember that, throughout this guide, we place the "TYPE" symbol
91 alongside pieces of code that we recommend you to type into your own
92 game files as you read through the examples (which, conversely, means
93 that you don't need to type the unmarked pieces of code). You'll learn
94 Inform more quickly by trying it for yourself, rather than just taking
95 our word for how things work.
99 Again, revisit the TYPE symbol. Maybe a standard indicator above
102 #. In the same folder, use your text editor to create the compilation
103 support file ``Heidi.bat`` (on a PC)::
105 ..\..\Lib\Base\Inform Heidi
106 +include_path=.\,..\..\Lib\Base,..\..\Lib\Contrib | more
108 pause "at end of compilation"
110 or ``Heidi.command`` (on a Macintosh)::
112 cd ~/Inform/Games/Heidi/
114 ../../Lib/Base/inform30_macosx Heidi
115 +include_path=./,../../Lib/Base,../../Lib/Contrib
117 Remember that there's just one space between "``Heidi``" and
120 Type in the file from scratch, or copy and edit ``MyGame1.bat`` (or
121 ``MyGame1.command``). At this point, you should have a ``Heidi`` folder
122 containing two files: ``Heidi.inf`` and either ``Heidi.bat`` or
125 #. Compile the source file ``Heidi.inf``; refer back to "Inform on an IBM
126 PC (running Microsoft Windows)" on page 19 or "Inform on an Apple
127 Macintosh (running OS X)" on page 24 for guidance. If the compilation
128 works, a story file ``Heidi.z5`` appears in the folder. If the
129 compilation *doesn't* work, you've probably made a typing mistake; check
130 everything until you find it.
132 #. You can run the story file in your Inform interpreter; you should see
133 this (except that the Serial number will be different -- it's based on
136 .. code-block:: transcript
139 A simple Inform example
140 by Roger Firth and Sonja Kesserich.
141 Release 1 / Serial number 040804 / Inform v6.30 Library 6/11 SD
144 It is pitch dark, and you can't see a thing.
148 When you get that far, your template source file is correct. Let's explain
151 Understanding the source file
152 =============================
154 Although we've got a certain amount of freedom of expression, source files
155 tend to conform to a standard overall structure: these lines at the start,
156 that material next, those pieces coming at the end, and so on. What we're
157 doing here is mapping out a structure that suits us, giving ourselves a
158 clear framework onto which the elements of the game can be fitted. Having
159 a clear (albeit sparse) map at the start will help us to keep things
160 organised as the game evolves. We can infer several Inform rules just by
161 looking at the source file.
163 * If the *very first line* (or lines) of the source file begin with the
164 characters "``!%``", then the compiler treats what follows on those lines
165 as control instructions to itself rather than as part of the game's
166 source. The instructions most commonly placed here are compiler
167 switches, a way of controlling detailed aspects of how the compiler
168 operates. These particular switches, two of many, are turning on
169 **Strict mode**, which makes the game less likely to misbehave when being
170 played, and **Debug mode**, which provides some extra commands which can
171 be helpful when tracking down problems.
175 Actually, the ``-S`` is redundant, since Strict mode is already on by
176 default. We include it here as a reminder that (a) to turn Strict
177 mode *off*, you change this setting to ``-~S``, and (b) alphabetic
178 case matters here: ``-s`` causes a display of compiler statistics (and
179 ``-~s`` does nothing at all).
181 * Otherwise, when the compiler comes across an exclamation mark, it ignores
182 the rest of the line. If the ``!`` is at the start of a line, the whole
183 line is ignored; if the ``!`` is halfway along a line, the compiler takes
184 note of the first half, and then ignores the exclamation mark and
185 everything after it on that line. We call material following an
186 exclamation mark, not seen by anybody else, a **comment**; it's often a
187 remark that we write to remind ourselves of how something works or why we
188 tackled a problem in a particular way. There's nothing special about
189 those equals signs: they just produce clear lines across the page.
191 It's always a good idea to comment code as you write it, for later it
192 will help you to understand what was going on at a particular spot.
193 Although it all seems clear in your head when you first write it, in a
194 few months you may suspect that a totally alien mind must have produced
195 that senseless gibberish.
197 By the way, the compiler *doesn't* give special treatment to exclamation
198 marks in quoted text: ``!`` within quotes "..." is treated as a normal
199 character. On this line, the first ``!`` is part of the sequence (or
200 string) of characters to be displayed:
202 .. code-block:: inform6
204 print "Hello world!"; ! <- is the start of this comment
206 * The compiler ignores blank lines, and treats lots of space like a single
207 space (except when the spaces are part of a character string). So, these
208 two rules tell us that we *could* have typed the source file like this:
210 .. code-block:: inform6
212 Constant Story "Heidi";
214 "^A simple Inform example^by Roger Firth and Sonja Kesserich.^";
215 Include "Parser";Include "VerbLib";
219 We didn't type it that way because, though shorter, it's much harder to
220 read. When designing a game, you'll spend a lot of time studying what
221 you've typed, so it's worthwhile taking a bit of care to make it as
222 readable as possible.
224 * Every game should have the **constant** definitions for ``Story`` (the
225 game's name) and ``Headline`` (typically, information on the game's
226 theme, copyright, authorship and so on). These two **string** values,
227 along with a release number and date, and details of the compiler,
228 compose the **banner** which is displayed at the start of each game.
230 * Every game needs the three lines which ``Include`` the standard library
231 files -- that is, they merge those files' contents into your source file:
233 .. code-block:: inform6
240 They always have to be in this order, with ``Parser`` and ``VerbLib``
241 near the start of the file, and ``Grammar`` near the end.
243 * Every game needs to define an ``Initialise`` routine (note the British
246 .. code-block:: inform6
250 The **routine** that we've defined here doesn't do anything useful, but
251 it still needs to be present. Later, we'll come back to ``Initialise``
252 and explain what a routine is and why we need this one.
254 * You'll notice that each of the items mentioned in the previous three
255 rules ends with a semicolon. Inform is very fussy about its punctuation,
256 and gets really upset if you forget a terminating semicolon. In fact,
257 the compiler just keeps reading your source file until it finds one;
258 that's why we were able to take three lines to define the ``Headline``
261 .. code-block:: inform6
264 "^A simple Inform example
265 ^by Roger Firth and Sonja Kesserich.^";
267 Just to repeat what we said earlier: every game that you design will start
268 out from a basic source file like this (in fact, it might be sensible to
269 keep a copy of this template file in a safe place, as a starting point for
270 future games). Think of this stuff as the basic preparation which you'll
271 quickly come to take for granted, much as a landscape artist always begins
272 by sizing the canvas before starting to paint. So, now that we've taken a
273 quick tour of Inform's general needs, we can start thinking about what this
274 particular game requires.
276 Defining the game's locations
277 =============================
279 A good starting point in any game is to think about the locations which are
280 involved: this sketch map shows the four that we'll use:
282 .. image:: /images/heidi1.*
285 In IF, we talk about each of these locations as a **room**, even though in
286 this example none of them has four walls. So let's use Inform to define
287 those rooms. Here's a first attempt:
289 .. code-block:: inform6
291 Object "In front of a cottage"
293 "You stand outside a cottage. The forest stretches east.",
296 Object "Deep in the forest"
298 "Through the dense foliage, you glimpse a building to the west.
299 A track heads to the northeast.",
302 Object "A forest clearing"
304 "A tall sycamore stands in the middle of this clearing.
305 The path winds southwest through the trees.",
308 Object "At the top of the tree"
309 with description "You cling precariously to the trunk.",
312 Again, we can infer some general principles from these four examples:
314 * A room definition starts with the word ``Object`` and ends, about four
315 lines later, with a semicolon. Each of the components that appears in
316 your game -- not only the rooms, but also the people, the things that you
317 see and touch, intangibles like a sound, a smell, a gust of wind -- is
318 defined in this way; think of an "object" simply as the general term for
319 the myriad thingies which together comprise the model world which your
322 * The phrase in double quotes following the word ``Object`` is the name
323 that the interpreter uses to provide the player character with a list of
324 the objects around her: where she is, what she can see, what she's
329 We're using the word "player" to mean both the person who is playing
330 the game, and the principal protagonist (often known as the player
331 character) within the game itself. Since the latter -- Heidi -- is
332 female, we'll refer to the player as "she" while discussing this game.
334 * A keyword ``with`` follows, which simply tells the compiler what to
337 * The word ``description``, introducing another piece of text which gives
338 more detail about the object: in the case of a room, it's the appearance
339 of the surrounding environment when the player character is in that room.
340 The textual description is given in double quotes, and is followed by a
343 * Near the end, the keyword ``has`` appears, which again tells the compiler
344 to expect a certain kind of information.
346 * The word ``light`` says that this object is a source of illumination, and
347 that therefore the player character can see what's happening here. There
348 has to be at least one light source in every room (unless you want the
349 player to be told that "It's pitch dark and you can't see a thing"); most
350 commonly, that light source is the room itself.
352 A smidgeon of background may help set this into context (there's more in
353 the next chapter). An object can have both **properties** (introduced by
354 the keyword ``with``) and **attributes** (written after the word ``has``).
355 A property has both a name (like ``description``) and a value (like the
356 character string "``You stand outside a cottage. The forest stretches
357 east.``"); an attribute has merely a name.
359 In a little while, when you play this game, you'll observe that it starts
362 .. code-block:: transcript
364 In front of a cottage
365 You stand outside a cottage. The forest stretches east.
367 And here you can see how the room's name (``In front of a cottage``) and
368 description (``You stand outside a cottage. The forest stretches east.``)
374 We said that this was a first attempt at defining the rooms; it's fine as
375 far as it goes, but a few bits of information are missing. If you look at
376 the game's sketch map, you can see how the rooms are intended to be
377 connected; from "Deep in the forest", for example, the player character
378 should be able to move west towards the cottage, or northeast to the
379 clearing. Now, although our descriptions mention or imply these available
380 routes, we also need to explicitly add them to the room definitions in a
381 form that the game itself can make sense of. Like this:
383 .. code-block:: inform6
385 Object before_cottage "In front of a cottage"
387 "You stand outside a cottage. The forest stretches east.",
391 Object forest "Deep in the forest"
393 "Through the dense foliage, you glimpse a building to the west.
394 A track heads to the northeast.",
399 Object clearing "A forest clearing"
401 "A tall sycamore stands in the middle of this clearing.
402 The path winds southwest through the trees.",
407 Object top_of_tree "At the top of the tree"
408 with description "You cling precariously to the trunk.",
412 We've made two changes to the room objects.
414 * First, between the word ``Object`` and the object's name in double
415 quotes, we've inserted a different type of name: a private, internal
416 identification, never seen by the player; one that we can use *within*
417 the source file when one object needs to refer to another object. For
418 example, the first room is identified as ``before_cottage``, and the
419 second as ``forest``.
421 Unlike the external name contained in double quotes, the internal
422 identifier has to be a single word -- that is, without spaces. To aid
423 readability, we often use an underscore character to act as sort of
424 pseudo-space: ``before_cottage`` is a bit clearer than ``beforecottage``.
426 * Second, we've added lines after the object descriptions which use those
427 internal identifiers to show how the rooms are connected; one line for
428 each connection. The ``before_cottage`` object has this additional
433 This means that a player standing in front of the cottage can type GO
434 EAST (or EAST, or just E), and the game will transport her to the room
435 whose internal identification is ``forest``. If she tries to move in any
436 other direction from this room, she'll be told "You can't go that way".
438 What we've just defined is a *one-way* easterly connection:
439 ``before_cottage`` → ``forest``. The forest object has two additional
445 The first line defines a westerly connection ``forest`` →
446 ``before_cottage`` (thus enabling the player character to return to the
447 cottage), and the second defines a connection ``forest`` → ``clearing``
448 which heads off to the northeast.
450 Inform provides for eight "horizontal" connections (``n_to``, ``ne_to``,
451 ``e_to``, ``se_to``, ``s_to``, ``sw_to``, ``w_to``, ``nw_to``) two
452 "vertical" ones (``u_to``, ``d_to``) and two specials ``in_to``, and
453 ``out_to``. You'll see some of these used for the remaining inter-room
456 There's one last detail to attend to before we can test what we've done.
457 You'll recollect that our story begins with Heidi standing in front of her
458 cottage. We need to tell the interpreter that ``before_cottage`` is the room
459 where the game starts, and we do this in the ``Initialise`` routine::
461 [ Initialise; location = before_cottage; ];
463 ``location`` is a **variable**, part of the library, which tells the
464 interpreter in which room the player character currently is. Here, we're
465 saying that, at the start of the game, the player character is in the
466 ``before_cottage`` room.
468 Now we can add what we've done to the ``Heidi.inf`` source file template.
469 At this stage, you should study the four room definitions, comparing them
470 with the sketch map until you're comfortable that you understand how to
471 create simple rooms and define the connections between them.
473 .. code-block:: inform6
475 !============================================================================
476 Constant Story "Heidi";
478 "^A simple Inform example
479 ^by Roger Firth and Sonja Kesserich.^";
484 !============================================================================
487 Object before_cottage "In front of a cottage"
489 "You stand outside a cottage. The forest stretches east.",
493 Object forest "Deep in the forest"
495 "Through the dense foliage, you glimpse a building to the west.
496 A track heads to the northeast.",
501 Object clearing "A forest clearing"
503 "A tall sycamore stands in the middle of this clearing.
504 The path winds southwest through the trees.",
509 Object top_of_tree "At the top of the tree"
510 with description "You cling precariously to the trunk.",
514 !============================================================================
515 ! Entry point routines
517 [ Initialise; location = before_cottage; ];
519 !============================================================================
520 ! Standard and extended grammar
524 !============================================================================
526 Type this in, as always taking great care with the punctuation -- watch
527 those commas and semicolons. Compile it, and fix any mistakes which the
528 compiler reports. You can then play the game in its current state.
529 Admittedly, you can't do very much, but you should be able to move freely
530 among the four rooms that you've defined.
534 In order to minimise the amount of typing that you have to do, the
535 descriptive text in this game has been kept as short as possible. In a
536 real game, you would typically provide more interesting descriptions
539 Adding the bird and the nest
540 ============================
542 Given what we said earlier, you won't be surprised to hear that both the
543 bird and its nest are Inform objects. We'll start their definitions like
546 .. code-block:: inform6
548 Object bird "baby bird"
549 with description "Too young to fly, the nestling tweets helplessly.",
552 Object nest "bird's nest"
553 with description "The nest is carefully woven of twigs and moss.",
556 You can see that these definitions have exactly the same format as the
557 rooms we defined previously: a one-word internal identifier (``bird``,
558 ``nest``), and a word or phrase naming the object for the player's benefit
559 (``baby bird``, ``bird's nest``). They both have some descriptive detail:
560 for a room this is printed when the player first enters, or when she types
561 LOOK; for other objects it's printed when she EXAMINEs that object. What
562 they *don't* have are connections (``e_to``, ``w_to``, etc. apply only to
563 rooms) or ``light`` (it's not necessary -- the rooms ensure that light is
566 When the game is running, the player will want to refer to these two
567 objects, saying for instance EXAMINE THE BABY BIRD or PICK UP THE NEST.
568 For this to work reliably, we need to specify the word (or words) which
569 relate to each object. Our aim here is flexibility: providing a choice of
570 relevant vocabulary so that the player can use whatever term seems
571 appropriate to her, with a good chance of it being understood. We add a
572 line to each definition:
574 .. code-block:: inform6
576 Object bird "baby bird"
577 with description "Too young to fly, the nestling tweets helplessly.",
578 name 'baby' 'bird' 'nestling',
581 Object nest "bird's nest"
582 with description "The nest is carefully woven of twigs and moss.",
583 name 'bird^s' 'nest' 'twigs' 'moss',
586 The ``name`` introduces a list in single quotes '...'. We call each of
587 those quoted things a **dictionary word**, and we do mean "word", not
588 "phrase" (``'baby'``\ ``'bird'`` rather than ``'baby bird'``); you can't
589 uses spaces, commas or periods in dictionary words, though there's a space
590 *between* each one, and the whole list ends with a comma. The idea is that
591 the interpreter decides which object a player is talking about by matching
592 what she types against the full set of all dictionary words. If the player
593 mentions BIRD, or BABY BIRD, or NESTLING, it's the ``baby bird`` that she
594 means; if she mentions NEST, BIRD'S NEST or MOSS, it's the ``bird's nest``.
595 And if she types NEST BABY or BIRD TWIGS, the interpreter will politely say
596 that it doesn't understand what on earth she's talking about.
600 You'll notice the use of ``'bird^s'`` to define the dictionary word
601 BIRD'S; this oddity is necessary because the compiler expects the single
602 quotes in the list always to come in pairs -- one at the start of the
603 dictionary word, and one at the end. If we had typed ``'bird's'`` then
604 the compiler would find the opening quote, the four letters ``b``,
605 ``i``, ``r`` and ``d``, and what looks like the closing quote. So far
606 so good; it's read the word BIRD and now expects a space before the next
607 opening quote... but instead finds ``s'`` which makes no sense. In
608 cases like this we must use the circumflex ``^`` to *represent* the
609 apostrophe, and the compiler then treats ``bird's`` as a dictionary
612 You may be wondering why we need a list of ``name`` words for the bird and
613 its nest, yet we didn't when we defined the rooms? It's because the player
614 can't interact with a room in the same way as with other objects; for
615 example, she doesn't need to say EXAMINE THE FOREST -- just being there and
616 typing LOOK is sufficient.
618 The bird's definition is complete, but there's an additional complexity
619 with the nest: we need to be able to put the bird into it. We do this by
620 labelling the nest as a ``container`` -- able to hold other objects -- so
621 that the player can type PUT (or INSERT) BIRD IN (or INTO) NEST.
622 Furthermore, we label it as ``open``; this prevents the interpreter from
623 asking us to open it before putting in the bird.
625 .. code-block:: inform6
627 Object nest "bird's nest"
628 with description "The nest is carefully woven of twigs and moss.",
629 name 'bird^s' 'nest' 'twigs' 'moss',
632 Both objects are now defined, and we can incorporate them into the game.
633 To do this, we need to choose the locations where the player will find
634 them. Let's say that the bird is found in the forest, while the nest is in
635 the clearing. This is how we set this up:
637 .. code-block:: inform6
639 Object bird "baby bird" forest
640 with description "Too young to fly, the nestling tweets helplessly.",
641 name 'baby' 'bird' 'nestling',
644 Object nest "bird's nest" clearing
645 with description "The nest is carefully woven of twigs and moss.",
646 name 'bird^s' 'nest' 'twigs' 'moss',
649 Read that first line as: "Here's the definition of an object which is
650 identified within this file as ``bird``, which is known to the player as
651 ``baby bird``, and which is initially located inside the object identified
652 within this file as ``forest``."
654 Where in the source file do these new objects fit? Well, anywhere really,
655 but you'll find it convenient to insert them following the rooms where
656 they're found. This means adding the bird just after the forest, and the
657 nest just after the clearing. Here's the middle piece of the source file:
659 .. code-block:: inform6
661 !============================================================================
664 Object before_cottage "In front of a cottage"
666 "You stand outside a cottage. The forest stretches east.",
670 Object forest "Deep in the forest"
672 "Through the dense foliage, you glimpse a building to the west.
673 A track heads to the northeast.",
678 Object bird "baby bird" forest
679 with description "Too young to fly, the nestling tweets helplessly.",
680 name 'baby' 'bird' 'nestling',
683 Object clearing "A forest clearing"
685 "A tall sycamore stands in the middle of this clearing.
686 The path winds southwest through the trees.",
691 Object nest "bird's nest" clearing
692 with description "The nest is carefully woven of twigs and moss.",
693 name 'bird^s' 'nest' 'twigs' 'moss',
696 Object top_of_tree "At the top of the tree"
697 with description "You cling precariously to the trunk.",
701 !============================================================================
703 Make those changes, recompile the game, play it and you'll see this:
705 .. code-block:: transcript
708 Through the dense foliage, you glimpse a building to the west. A track heads
711 You can see a baby bird here.
715 Adding the tree and the branch
716 ==============================
718 The description of the clearing mentions a tall sycamore tree, up which the
719 player character supposedly "climbs". We'd better define it:
721 .. code-block:: inform6
723 Object tree "tall sycamore tree" clearing
725 "Standing proud in the middle of the clearing,
726 the stout tree looks easy to climb.",
727 name 'tall' 'sycamore' 'tree' 'stout' 'proud',
730 Everything there should be familiar, apart from that ``scenery`` at the
731 end. We've already mentioned the tree in the description of the forest
732 clearing, so we don't want the interpreter adding "You can see a tall
733 sycamore tree here" afterwards, as it does for the bird and the nest. By
734 labelling the tree as ``scenery`` we suppress that, and also prevent it
735 from being picked up by the player character. One final object: the branch
736 at the top of the tree. Again, not many surprises in this definition:
738 .. code-block:: inform6
740 Object branch "wide firm bough" top_of_tree
741 with description "It's flat enough to support a small object.",
742 name 'wide' 'firm' 'flat' 'bough' 'branch',
743 has static supporter;
745 The only new things are those two labels. ``static`` is similar to
746 ``scenery``: it prevents the branch from being picked up by the player
747 character, but *doesn't* suppress mention of it when describing the
748 setting. And ``supporter`` is rather like the ``container`` that we used
749 for the nest, except that this time the player character can put other
750 objects *onto* the branch. (In passing, we'll mention that an object can't
751 normally be both a ``container`` and a ``supporter``.) And so here are our
754 .. code-block:: inform6
756 !============================================================================
759 Object before_cottage "In front of a cottage"
761 "You stand outside a cottage. The forest stretches east.",
765 Object forest "Deep in the forest"
767 "Through the dense foliage, you glimpse a building to the west.
768 A track heads to the northeast.",
773 Object bird "baby bird" forest
774 with description "Too young to fly, the nestling tweets helplessly.",
775 name 'baby' 'bird' 'nestling',
778 Object clearing "A forest clearing"
780 "A tall sycamore stands in the middle of this clearing.
781 The path winds southwest through the trees.",
786 Object nest "bird's nest" clearing
787 with description "The nest is carefully woven of twigs and moss.",
788 name 'bird^s' 'nest' 'twigs' 'moss',
791 Object tree "tall sycamore tree" clearing
793 "Standing proud in the middle of the clearing,
794 the stout tree looks easy to climb.",
795 name 'tall' 'sycamore' 'tree' 'stout' 'proud',
798 Object top_of_tree "At the top of the tree"
799 with description "You cling precariously to the trunk.",
803 Object branch "wide firm bough" top_of_tree
804 with description "It's flat enough to support a small object.",
805 name 'wide' 'firm' 'flat' 'bough' 'branch',
806 has static supporter;
808 !============================================================================
810 Once again, make the changes, recompile, and investigate what you can do in
816 Our first pass at the game is nearly done; just two more changes to
817 describe. The first is easy: Heidi wouldn't be able to climb the tree
818 carrying the bird and the nest separately: we want the player character to
819 put the bird into the nest first. One easy way to enforce this is by
820 adding a line near the top of the file:
822 .. code-block:: inform6
824 !============================================================================
825 Constant Story "Heidi";
827 "^A simple Inform example
828 ^by Roger Firth and Sonja Kesserich.^";
830 Constant MAX_CARRIED 1;
832 The value of ``MAX_CARRIED`` limits the number of objects that the player
833 character can be holding at any one time; by setting it to 1, we're saying
834 that she can carry the bird or the nest, but not both. However, the limit
835 ignores the contents of ``container`` or ``supporter`` objects, so the nest
836 with the bird inside it is still counted as one object.
838 The other change is slightly more complex and more important: there's
839 currently no way to "win" the game! The goal is for the player character
840 to put the bird in the nest, take the nest to the top of the tree, and
841 place it on the branch; when that happens, the game should be over. This
842 is one way of making it happen:
844 .. code-block:: inform6
846 Object branch "wide firm bough" top_of_tree
847 with description "It's flat enough to support a small object.",
848 name 'wide' 'firm' 'flat' 'bough' 'branch',
849 each_turn [; if (nest in branch) deadflag = 2; ],
850 has static supporter;
854 Here's an explanation of what's going on. If you find this difficult to
855 grasp, don't worry. It's the hardest bit so far, and it introduces
856 several new concepts all at once. Later in the guide, we'll explain
857 those concepts more clearly, so you can just skip this bit if you want.
859 The variable ``deadflag``, part of the library, is normally 0. If you set
860 its value to 2, the interpreter notices and ends the game with "You have
861 won". The statement::
863 if (nest in branch) deadflag = 2;
865 should be read as: "Test whether the ``nest`` is currently in the
866 ``branch`` (if the branch is a ``container``) or on it (if the
867 ``branch`` is a supporter); if it is, set the value of ``deadflag`` to
868 2; if it isn't, do nothing." The surrounding part::
872 should be read as: "At the end of each turn (when the player is in the
873 same room as the branch), do whatever is written inside the square
874 brackets". So, putting that all together:
876 * At the end of each turn (after the player has typed something and
877 pressed the Enter key, and the interpreter has done whatever was
878 requested) the interpreter checks whether the player and the
879 ``branch`` are in the same room. If not, nothing happens. If they're
880 together, it looks to see where the nest is. Initially it's in the
881 ``clearing``, so nothing happens.
883 * Also at the end of each turn, the interpreter checks the value of
884 ``deadflag``. Usually it's 0, so nothing happens.
886 * Finally the player character puts the ``nest`` on the ``branch``.
887 "Aha!" says the interpreter (to itself, of course), and sets the
888 value of ``deadflag`` to 2.
890 * Immediately afterwards, (another part of) the interpreter checks and
891 finds that the value of ``deadflag`` has changed to 2, which means
892 that the game is successfully completed; so, it says to the player,
895 That's as far as we'll take this example for now. Make those final
896 changes, recompile, and test what you've achieved. You'll probably find a
897 few things that could be done better -- even on a simple game like this
898 there's considerable scope for improvement -- so we'll revisit Heidi in her
899 forest shortly. First, though, we'll recap what we've learnt so far.