X-Git-Url: https://jxself.org/git/?p=ibg.git;a=blobdiff_plain;f=chapters%2F10.rst;h=6c785f995dab37fa79857e3a0da0395efc470f6e;hp=d0c9638bde1cdf99db729f82477832e2bfe41e83;hb=fb8b7c14f10733e913e2b87f9a82e5b44c0dc7be;hpb=9e9feffd79cc1c4aa9c387afe98e16c7fbfae78d diff --git a/chapters/10.rst b/chapters/10.rst index d0c9638..6c785f9 100644 --- a/chapters/10.rst +++ b/chapters/10.rst @@ -4,23 +4,19 @@ Captain Fate: take 1 .. epigraph:: - | *S was a sailor, and spent all he got;* - | *T was a tinker, and mended a pot.* + | |CENTER| *S was a sailor, and spent all he got;* + | |CENTER| *T was a tinker, and mended a pot.* .. only:: html .. image:: /images/picS.png :align: left -.. raw:: latex - - \dropcap{s} - -imple though they are, our two games have covered most of the basic -functionality of Inform, providing enough solid ground underfoot -for you to start creating simple stories. Even if some of what you've -encountered doesn't make sense yet, you should be able to browse a -game's source code and form a general understanding of what is going on. +|S|\imple though they are, our two games have covered most of the basic +functionality of Inform, providing enough solid ground underfoot for you to +start creating simple stories. Even if some of what you've encountered +doesn't make sense yet, you should be able to browse a game's source code +and form a general understanding of what is going on. We'll now design a third game, to show you a few additional features and give you some more sample code to analyse. In "Heidi" we tried to make @@ -32,8 +28,7 @@ information in logical didactic chunks, defining some of the objects minimally at first and then adding complexity as need arises. Again, this means that you won't be able to compile for testing purposes after the addition of every code snippet, so, if you're typing in the game as -you read, you’ll need to check the advice in "Compile-as-you-go" on page -255. +you read, you’ll need to check the advice in :ref:`compile-as-you-go`. A lot of what goes into this game we have already seen; you may deduce from this that the game design business is fairly repetitious and that @@ -46,11 +41,11 @@ super-hero made famous by a childhood of comic books: .. pull-quote:: - "Impersonating mild mannered John Covarth, assistant help boy at - an Impersonating insignificant drugstore, you suddenly STOP - when your acute hearing deciphers a stray radio call from the - POLICE. There’s some MADMAN attacking the population in Granary - Park! You must change into your Captain FATE costume fast...!" + "Impersonating mild mannered John Covarth, assistant help boy at an + insignificant drugstore, you suddenly STOP when your acute hearing + deciphers a stray radio call from the POLICE. There’s some MADMAN + attacking the population in Granary Park! You must change into your + Captain FATE costume fast...!" which won't be so easy to do. In this short example, players will win when they manage to change into their super-hero costume and fly away to @@ -65,7 +60,7 @@ Fade up on: a nondescript city street The game starts with meek John Covarth walking down the street. We set up the game as usual: -.. code-block:: inform6 +.. code-block:: inform !% -SD !============================================================================ @@ -132,7 +127,7 @@ up the game as usual: Almost everything is familar, apart from a few details: -.. code-block:: inform6 +.. code-block:: inform Constant MANUAL_PRONOUNS; Constant MAX_SCORE 2; @@ -154,11 +149,11 @@ Tell", which defines the maximum number of points to be scored, we now see two more constants: ``OBJECT_SCORE`` and ``ROOM_SCORE``. There are several scoring systems predefined in Inform. In "William Tell" we've seen how you can manually add (or subtract) points by changing the value -of the variable ``score``. Another approach is to award points to +of the variable :var:`score`. Another approach is to award points to players on the first occasion that they (a) enter a particular room, or (b) pick up a particular object. To define that a room or object is indeed “particular”, all you have to do is give it the attribute -``scored``; the library take cares of the rest. The predefined scores +:attr:`scored`; the library take cares of the rest. The predefined scores are five points for finally reached rooms and four points for wondrous acquisition of objects. With the constants ``OBJECT_SCORE`` and ``ROOM_SCORE`` we can change those defaults; for the sake of example, @@ -166,7 +161,7 @@ we've decided to modestly award one point for each. By the way, the use of an equals sign ``=`` is optional with ``Constant``; these two lines have identical effect: -.. code-block:: inform6 +.. code-block:: inform Constant ROOM_SCORE 1; @@ -176,7 +171,7 @@ Another difference has to do with a special short-hand method that Inform provides for displaying strings of text. Until now, we have shown you: -.. code-block:: inform6 +.. code-block:: inform print "And now for something completely different...^"; return true; ... @@ -187,7 +182,7 @@ newline character, and return true. As you have seen in the previous example games, this happens quite a lot, so there is a yet shorter way of achieving the same result: -.. code-block:: inform6 +.. code-block:: inform "And now for something completely different..."; @@ -202,9 +197,9 @@ has been displayed on the screen -- we should use the explicit ``print`` statement instead. You'll notice that -- unusually for a room -- our ``street`` object has -a ``name`` property: +a :prop:`name` property: -.. code-block:: inform6 +.. code-block:: inform Room street "On the street" with name 'city' 'buildings' 'skyscrapers' 'shops' 'apartments' 'cars', @@ -217,17 +212,17 @@ EXAMINE CITY here, the interpreter will reply "That's not something you need to refer to in order to SAVE the day", rather than the misleading "You can't see any such thing". We mostly prefer to deal with such scenic words using classes like ``Prop`` and ``Furniture``, but -sometimes a room's ``name`` property is a quick and convenient solution. +sometimes a room's :prop:`name` property is a quick and convenient solution. In this game, we provide a class named ``Appliance`` to take care of furniture and unmovable objects. You’ll notice that the starting room we have defined has no connections yet. The description mentions a phone booth and a café, so we might want to code those. While the café will be a normal room, it would seem logical that the phone booth is actually a -big box on the sidewalk; therefore we define a ``container`` set in the +big box on the sidewalk; therefore we define a :attr:`container` set in the street, which players may enter: -.. code-block:: inform6 +.. code-block:: inform Appliance booth "phone booth" street with name 'old' 'red' 'picturesque' 'phone' 'booth' 'cabin' @@ -248,20 +243,20 @@ street, which players may enter: has enterable container open; What's interesting are the attributes at the end of the definition. -You'll recall from Heidi's ``nest`` object that a ``container`` is an +You'll recall from Heidi's ``nest`` object that a :attr:`container` is an object capable of having other objects placed in it. If we make -something ``enterable``, players count as one of those objects, so that +something :attr:`enterable`, players count as one of those objects, so that they may squeeze inside. Finally, ``containers`` are, by default, -supposed to be closed. You can make them ``openable`` if you wish +supposed to be closed. You can make them :attr:`openable` if you wish players to be able to OPEN and CLOSE them at will, but this doesn't seem appropriate behaviour for a public cabin -- it would become tedious to have to type OPEN BOOTH and CLOSE BOOTH when these actions provide -nothing special -- so we add instead the attribute ``open`` (as we did +nothing special -- so we add instead the attribute :attr:`open` (as we did with the nest), telling the interpreter that the container is open from the word go. Players aren't aware of our design, of course; they may indeed try to OPEN and CLOSE the booth, so we trap those actions in a -``before`` property which just tells them that these are not relevant -options. The ``after`` property gives a customised message to override +:prop:`before` property which just tells them that these are not relevant +options. The :prop:`after` property gives a customised message to override the library’s default for commands like ENTER BOOTH or GO INSIDE BOOTH. Since in the street's description we have told players that the phone @@ -270,7 +265,7 @@ intercept this attempt and redirect it (while we're at it, we add a connection to the as-yet-undefined café room and a default message for the movement which is not allowed): -.. code-block:: inform6 +.. code-block:: inform Room street "On the street" with name city' 'buildings' 'skyscrapers' 'shops' 'apartments' 'cars', @@ -284,20 +279,14 @@ the movement which is not allowed): "No time now for exploring! You'll move much faster in your Captain FATE costume."; -.. todo:: - - Notice how the syntax coloring thinks that the exclaimation point - above is a comment. This is another problem with the built-in inform6 - syntax highlighter. - That takes care of entering the booth. But what about leaving it? Players may type EXIT or OUT while they are inside an enterable container and the interpreter will oblige but, again, they might type NORTH. This is a problem, since we are actually in the street (albeit inside the booth) and to the north we have the café. We may provide for -this condition in the room's ``before`` property: +this condition in the room's :prop:`before` property: -.. code-block:: inform6 +.. code-block:: inform before [; Go: @@ -310,7 +299,7 @@ connection. However, that would be an ambiguous command, for it could also refer to the café, so we express our bafflement and force the player to try something else: -.. code-block:: inform6 +.. code-block:: inform n_to cafe, s_to [; <>; ], @@ -318,7 +307,7 @@ player to try something else: Now everything seems to be fine, except for a tiny detail. We've said that, while in the booth, the player character’s location is still the -``street`` room, regardless of being inside a ``container``; if players +``street`` room, regardless of being inside a :attr:`container`; if players chanced to type LOOK, they'd get: .. code-block:: transcript @@ -330,19 +319,19 @@ chanced to type LOOK, they'd get: Hardly an adequate description while *inside* the booth. There are several ways to fix the problem, depending on the result you wish to -achieve. The library provides a property called ``inside_description`` +achieve. The library provides a property called :prop:`inside_description` which you can utilise with enterable containers. It works pretty much -like the normal ``description`` property, but it gets printed only when +like the normal :prop:`description` property, but it gets printed only when the player is inside the container. The library makes use of this property in a very clever way, because for every LOOK action it checks whether we can see outside the container: if the container has the -``transparent`` attribute set, or if it happens to be ``open``, the -library displays the normal ``description`` of the room first and then -the ``inside_description`` of the container. If the library decides we +:attr:`transparent` attribute set, or if it happens to be :attr:`open`, the +library displays the normal :prop:`description` of the room first and then +the :prop:`inside_description` of the container. If the library decides we can’t see outside the container, only the inside_description is displayed. Take for instance the following (simplified) example: -.. code-block:: inform6 +.. code-block:: inform Room stage "On stage" with description @@ -382,13 +371,13 @@ If now the player closes the box and LOOKs: In our case, however, we don't wish the description of the street to be displayed at all (even if a caller is supposedly able to see the street while inside a booth). The problem is that we have made the booth an -``open`` container, so the street's description would be displayed every -time. There is another solution. We can make the ``description`` +:attr:`open` container, so the street's description would be displayed every +time. There is another solution. We can make the :prop:`description` property of the ``street`` room a bit more complex, and change its value: instead of a string, we write an embedded routine. Here's the (almost) finished room: -.. code-block:: inform6 +.. code-block:: inform Room street "On the street" with name 'city' 'buildings' 'skyscrapers' 'shops' 'apartments' 'cars', @@ -415,7 +404,7 @@ value: instead of a string, we write an embedded routine. Here's the The description while inside the booth mentions the sidewalk, which might invite the player to EXAMINE it. No problem: -.. code-block:: inform6 +.. code-block:: inform Appliance "sidewalk" street with name sidewalk' 'pavement' 'street', @@ -432,7 +421,7 @@ result of a LOOK action (which will have to do with the way the café looks from the *inside*); but while we are on the street we need something else to describe it: -.. code-block:: inform6 +.. code-block:: inform Appliance outside_of_cafe "Benny's cafe" street with name 'benny^s' 'cafe' 'entrance', @@ -448,21 +437,23 @@ something else to describe it: ], has enterable proper; +.. index:: accented characters + .. note:: - although the text of our guide calls Benny's establishment a "café" - -- note the acute "e" -- the game itself simplifies this to "cafe". - We do this for clarity, not because Inform doesn't support accented - characters. The *Inform Designer's Manual* explains in detail how to - display these characters in "§1.11 *How text is printed*" and - provides the whole Z-machine character set in Table 2. In our case, - we could have displayed this:: + Although the text of our guide calls Benny's establishment a "café" -- + note the acute "e" -- the game itself simplifies this to "cafe". We do + this for clarity, not because Inform doesn't support accented + characters. The |DM4| explains in detail how to display these characters + in :dm4:`§1.11 ` "*How text is printed*" and provides the + whole Z-machine character set in Table 2. In our case, we could have + displayed this:: The town's favourite for a quick snack, Benny's café has a 50's ROCKETSHIP look. - by defining the ``description`` property as any of these: + by defining the :prop:`description` property as any of these: - .. code-block:: inform6 + .. code-block:: inform description "The town's favourite for a quick snack, Benny's caf@'e has a 50's @@ -482,40 +473,38 @@ something else to describe it: Unlike the sidewalk object, we offer more than a mere description. Since the player may try ENTER CAFE as a reasonable way of access -- which would have confused the interpreter immensely -- we take the opportunity -of making this object also ``enterable``, and we cheat a little. The -attribute ``enterable`` has permitted the verb ENTER to be applied to -this object, but this is not a ``container``; we want the player to be -sent into the *real* café room instead. The ``before`` property handles +of making this object also :attr:`enterable`, and we cheat a little. The +attribute :attr:`enterable` has permitted the verb ENTER to be applied to +this object, but this is not a :attr:`container`; we want the player to be +sent into the *real* café room instead. The :prop:`before` property handles this, intercepting the action, displaying a message and teleporting the player into the café. We ``return true`` to inform the interpreter that we have taken care of the ``Enter`` action ourselves, so it can stop right there. As a final detail, note that we now have two ways of going into the -café: the ``n_to`` property of the ``street`` room and the ``Enter`` +café: the :prop:`n_to` property of the ``street`` room and the ``Enter`` action of the ``outside_of_cafe`` object. A perfectionist might point out that it would be neater to handle the actual movement of the player in just one place of our code, because this helps clarity. To achieve -this, we redirect the street's ``n_to`` property thus: +this, we redirect the street's :prop:`n_to` property thus: -.. code-block:: inform6 +.. code-block:: inform n_to [; <>; ], -You may think that this is unnecessary madness, but a word to the wise: -in a large game, you want action handling going on just in one place -when possible, because it will help you to keep track of where things -are a-happening if something goes *ploof* (as, believe us, it will; see -"Debugging your game" on page 197). You don't need to be a -perfectionist, just cautious. - -A booth in this kind of situation is an open invitation for the player -to step inside and try to change into Captain Fate's costume. We won't -let this happen -- the player isn't Clark Kent, after all; later we'll -explain how we forbid this action -- and that will force the player to -go inside the café, looking for a discreet place to disrobe; but first, -let''s freeze John Covarth outside Benny''s and reflect about a -fundamental truth. +You may think that this is unnecessary madness, but a word to the wise: in +a large game, you want action handling going on just in one place when +possible, because it will help you to keep track of where things are +a-happening if something goes *ploof* (as, believe us, it will; see +:doc:`16`). You don't need to be a perfectionist, just cautious. + +A booth in this kind of situation is an open invitation for the player to +step inside and try to change into Captain Fate's costume. We won't let +this happen -- the player isn't Clark Kent, after all; later we'll explain +how we forbid this action -- and that will force the player to go inside +the café, looking for a discreet place to disrobe; but first, let's freeze +John Covarth outside Benny's and reflect about a fundamental truth. A hero is not an ordinary person ================================ @@ -530,15 +519,15 @@ a normal gaming situation; each displays an all-purpose message, sufficiently non-committal, and that's it. Of course, if your game includes a magic portal that will reveal itself only if the player lets rip with a snatch of Wagner, you may intercept the ``Sing`` action in a -``before`` property and alter its default, pretty useless behaviour. If +:prop:`before` property and alter its default, pretty useless behaviour. If not, it's "Your singing is abominable" for you. -All actions, useful or not, have a stock of messages associated with -them (the messages are held in the ``english.h`` library file and listed -in Appendix 4 of the *Inform Designer's Manual*). We have already seen -one way of altering the player character's description -- "As good -looking as ever" -- in "William Tell", but the other defaults may also -be redefined to suit your tastes and circumstantial needs. +All actions, useful or not, have a stock of messages associated with them +(the messages are held in the ``english.h`` library file and listed in +:dm4:`Appendix 4 ` of the |DM4|). We have already seen one way of +altering the player character's description -- "As good looking as ever" -- +in "William Tell", but the other defaults may also be redefined to suit +your tastes and circumstantial needs. John Covarth, aka Captain Fate, could happily settle for most of these default messages, but we deem it worthwhile to give him some customised @@ -546,7 +535,7 @@ responses. If nothing else, this adds to the general atmosphere, a nicety that many players regard as important. For this mission, we make use of the ``LibraryMessages`` object. -.. code-block:: inform6 +.. code-block:: inform Include "Parser"; @@ -585,7 +574,7 @@ use of the ``LibraryMessages`` object. If you provide it, the ``LibraryMessages`` object must be defined *between* the inclusion of ``Parser`` and ``VerbLib`` (it won't work otherwise and you’ll get a compiler error). The object contains a single -property -- ``before`` -- which intercepts display of the default +property -- :prop:`before` -- which intercepts display of the default messages that you want to change. An attempt to SING, for example, will now result in "Alas! That is not one of your many superpowers" being displayed. @@ -599,16 +588,11 @@ of responses. The variable ``lm_n`` holds the current value of the number of the message to be displayed, so you can change the default with a test like this: -.. code-block:: inform6 +.. code-block:: inform if (lm_n == 39) "That's not something you need to refer to in order to SAVE the day."; -.. todo:: - - That block of code above should be colored. Is there a defect in the - syntax highlighting code? - where 39 is the number for the standard message "That's not something you need to refer to in the course of this game" -- displayed when the player mentions a noun which is listed in a room's name property, as we @@ -616,11 +600,11 @@ did for the ``street``. .. note:: - remember that when we are testing for different values of the + Remember that when we are testing for different values of the same variable, we can also use the switch statement. For the Miscellany entry, the following code would work just as nicely: - .. code-block:: inform6 + .. code-block:: inform ... Miscellany: @@ -657,20 +641,22 @@ opt for the not-so-hot approach for some overriding reason. Don't feel discouraged; choices like this become more common (and easier) as your experience grows. -.. todo:: +.. Ugh. Ghastly, but it does the job. + +.. |WNL_LATEX| replace:: :latex:`\emph{\textbf{whatever new look}}` - That "whatever new look" below needs to be italicized and bolded for LaTeX +.. |WNL_HTML| replace:: :html:`whatever new look` .. note:: - going back to our example, an alternative approach would be to set - the variable ``player.description`` in the ``Initialise`` routine (as we - did with "William Tell") to the "ordinary clothes" string, and then - later change it as the need arises. It is a variable, after all, and you - can alter its value with another statement like ``player.description =`` - *whatever new look* anywhere in your code. This alternative solution - might be better if we intended changing the description of the player - many times through the game. Since we plan to have only two states, the + Going back to our example, an alternative approach would be to set the + variable ``player.description`` in the ``Initialise`` routine (as we did + with "William Tell") to the "ordinary clothes" string, and then later + change it as the need arises. It is a variable, after all, and you can + alter its value with another statement like ``player.description =`` + |WNL_LATEX| |WNL_HTML| anywhere in your code. This alternative solution + might be better if we intended changing the description of the player + many times through the game. Since we plan to have only two states, the ``LibraryMessages`` approach will do just fine. A final warning: as we explained when extending the standard verb @@ -679,7 +665,7 @@ the default messages, but that wouldn't be a sound practice, because your library file will probably not be right for the next game. Use of the ``LibraryMessages`` object is strongly advised. -If you're typing in the game, you'll probably want to read the brief -section on "Compile-as-you-go" on page 255 prior to performing a test -compile. Once everything's correct, it’s time that our hero entered that -enticing café. +If you're typing in the game, you'll probably want to read the brief +section on :ref:`compile-as-you-go` prior to performing a test compile. +Once everything's correct, it’s time that our hero entered that enticing +café.