1
<HTML><HEAD><TITLE>Section 19: Starting, moving, changing and killing the player</TITLE></HEAD>
2
<BODY BGCOLOR="#FFFFFF">
5
<TR><TD Valign="top"><A HREF="contents.html">Contents</A><BR><A HREF="section18.html">Back</A><BR><A HREF="section20.html">Forward</A><TD bgcolor="#F5DEB3"><BLOCKQUOTE><H3>19. Starting, moving, changing and killing the player</H3></BLOCKQUOTE><TR><TD><TD>
9
There are only three events in a man's life; birth, life and death;
10
he is not conscious of being born, he dies in pain and he forgets
12
<P>...Jean de la Bruyére (<B>1645</B>--<B>1696</B>)</BLOCKQUOTE>
14
<BR>Life's but a walking shadow, a poor player
15
<BR>That struts and frets his hour upon the stage
16
<BR>And then is heard no more; it is a tale
17
<BR>Told by an idiot, full of sound and fury,
18
<BR>Signifying nothing.
19
<BR><P>...William Shakespeare (<B>1564</B>--<B>1616</B>), <I>Macbeth V. v</I></BLOCKQUOTE>
23
The only compulsory task for a game's <TT>Initialise</TT> routine is to
24
set the <TT>location</TT> variable to the place where the player should begin.
25
This is usually a room (and is permitted to be one that's in darkness)
26
but could instead be an object inside a room, such as a chair or a bed.
27
If you would like to give the player some items to begin with, <TT>Initialise</TT>
28
should also <TT>move</TT> them to <TT>player</TT>.
31
Games with a long opening sequence might want to start by offering the player
32
a chance to restore a saved game at once. They can do so by writing the
33
following in their <TT>Initialise</TT> routines:
35
print "Would you like to restore a game? >";
36
if (YesOrNo()) <Restore>;
40
(If you want to make the status line invisible during an opening sequence, see
41
<A HREF="section33.html">Section 33</A>.) <TT>Initialise</TT> normally returns 0 or 1 (it doesn't matter which), but
42
if it returns 2 then no game banner will be printed at once. (This is for
43
games which, like 'Sorcerer', delay their banners until after the prologue.)
44
'Ruins', however, opens in classical fashion:
49
move food_ration to player;
50
move sodium_lamp to player;
51
move dictionary to player;
52
thedark.description = "The darkness of ages presses in on you, and you
53
feel claustrophobic.";
54
"^^^^^Days of searching, days of thirsty hacking through the briars of
55
the forest, but at last your patience was rewarded. A discovery!^";
60
(The <TT>TitlePage</TT> routine will be an exercise in <A HREF="section33.html">Section 33</A>: 'Ruins' is really
61
too small a game to warrant one, but never mind.)
62
The <TT>location</TT> variable needs some explanation. It holds either the current
63
room, if there's light to see by, or the special value <TT>thedark</TT> (the
64
"Darkness'' object) if there isn't. In the latter case (but only in the
65
latter case) the actual current room is held in the variable <TT>real_location</TT>,
66
should you need to know it. Neither of these is necessarily the same as
67
the parent of the <TT>player</TT> object. For instance, if the player sits in a
68
jeep parked in a dark garage, then <TT>location</TT> is <TT>thedark</TT>, <TT>real_location</TT>
69
is <TT>Garage</TT> and <TT>parent(player)</TT> is <TT>jeep</TT>.
72
Because of this, one shouldn't simply <TT>move</TT> the player object by hand.
73
Instead, to move the player about (for teleportation of some kind),
74
use the routine <TT>PlayerTo(place);</TT> (which automatically takes care of
75
printing the new room's description if there's enough light there to see
79
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> <TT>PlayerTo</TT> can also be used to move the player to a <TT>place</TT> inside
80
a room (e.g., a cage, or a traction engine).
84
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> Calling <TT>PlayerTo(place, 1);</TT> moves the player but prints
85
nothing (in particular, prints no room description).
89
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> Calling <TT>PlayerTo(place, 2);</TT> will <TT>Look</TT> as if the player had
90
arrived in the room by walking in as usual, so only a short description
91
appears if the room is one that has been seen before.
95
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> In a process called 'scoring arrival', a room which the player has entered
96
for the first time is given the <TT>visited</TT> attribute. If it was listed
97
as <TT>scored</TT>, points are awarded. (See <A HREF="section14.html">Section 14</A>.)
101
<P><TR><TD Valign="top"><IMG SRC="icons/ddbend.gif" ALT="/\/\"><TD bgcolor="#EEEEEE"><SMALL> When a <TT>Look</TT> action takes place, or a call to <TT>PlayerTo(place,1)</TT>,
102
the library 'notes arrival' as well as 'scores arrival'.
103
'Noting arrival' consists of checking to see if the room has changed
104
since last time (darkness counting as a different room for this purpose).
105
If so, the following happens:
107
<P>1. -- If the new location has an <TT>initial</TT> property, this is printed
108
if it's a string, or run if it's a routine.
109
<P>2. -- The entry point <TT>NewRoom</TT> is called (if it exists).
110
<P>3. -- Any 'floating objects', such as drifting mist, which are <TT>found_in</TT>
111
many places at once, are moved into the room.
118
The player's whole persona can easily be changed, because the player object
119
can itself have an <TT>orders</TT> routine, just as the object for any non-player
120
character can. To replace the <TT>orders</TT> routine for the standard <TT>player</TT>
123
player.orders = MyNewRule;
126
where <TT>MyNewRule</TT> is a new <TT>orders</TT> rule. Note that this is applied to
127
every action or order issued by the player. The variable <TT>actor</TT> holds the
128
person being told to do something, which may well be the player himself,
129
and the variables <TT>action</TT>, <TT>noun</TT> and <TT>second</TT> are set up as usual.
130
For instance, if a cannon goes off right next to the player,
131
a period of partial deafness might ensue:
134
if (actor~=player) rfalse;
135
Listen: "Your hearing is still weak from all that cannon-fire.";
139
The <TT>if</TT> statement needs to be there to prevent commands like
140
"helena, listen'' from being ruled out -- after all, the player
144
<P><TR><TD Valign="top"><IMG SRC="icons/dexercise.gif" ALT="??/\"><TD bgcolor="#FBB9AC"><A NAME="ex42"><B>EXERCISE 42:</B><BR>(link to <A HREF="answers1/answer42.html">the answer</A>)<TR><TD><TD> Why not achieve the same effect by giving the player
145
a <TT>react_before</TT> rule instead?
148
<P><TR><TD Valign="top"><IMG SRC="icons/exercise.gif" ALT="??"><TD bgcolor="#FBB9AC"><A NAME="ex43"><B>EXERCISE 43:</B><BR>(link to <A HREF="answers1/answer43.html">the answer</A>)<TR><TD><TD> (Cf. 'Curses'.) Write an <TT>orders</TT> routine for the player
149
so that wearing the gas mask will prevent him from
155
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> In fact a much more powerful trick is available: the <TT>player</TT> can
156
actually become a different character in the game, allowing the real player
157
at the keyboard to act through someone else.
158
Calling <TT>ChangePlayer(obj)</TT> will transform the player to <TT>obj</TT>. There's
159
no need for <TT>obj</TT> to have names like "me'' or "myself''; the
160
parser understands these words automatically to refer to the
161
currently-inhabited <TT>player</TT> object. However, it must provide a <TT>number</TT>
162
property (which the library will use for workspace). The maximum number
163
of items the player can carry as that object will be its <TT>capacity</TT>. Finally,
164
since <TT>ChangePlayer</TT> prints nothing, you may want to conclude with a <TT><<Look>>;</TT>
168
<TR><TD><TD bgcolor="#EEEEEE"><SMALL> <TT>ChangePlayer</TT> has many possible applications. The player
169
who tampers with Dr Frankenstein's brain transference machine may
170
suddenly become the Monster strapped to the table. A player who drinks
171
too much wine could become a 'drunk player object' to whom many different
172
rules apply. The "snavig'' spell of 'Spellbreaker', which transforms
173
the player to an animal like the one cast upon, could be implemented thus.
174
More ambitiously, a game could have a stock of half a dozen main characters,
175
and the focus of play can switch between them. A player might have a team
176
of four adventurers to explore a dungeon, and be able to switch the one
177
being controlled by typing the name. In this case, an <TT>AfterLife</TT> routine
178
-- see below -- may be needed to switch the focus back to a still-living
179
member of the team after one has met a sticky end.
182
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> Calling <TT>ChangePlayer(object,1);</TT> will do the same but make the
183
game print "(as Whoever)'' during room descriptions.
187
<P><TR><TD Valign="top"><IMG SRC="icons/ddbend.gif" ALT="/\/\"><TD bgcolor="#EEEEEE"><SMALL> When the person to be changed into has an <TT>orders</TT> routine,
188
things start to get complicated. It may be useful to arrange such a
193
{ ! I am the player object...
195
{ ! ...giving myself an order, i.e., trying an action.
198
{ ! ...giving someone else, the "actor", an order.
202
{ ! The player is the "actor" and is giving me an order.
211
<P><TR><TD Valign="top"><IMG SRC="icons/dexercise.gif" ALT="??/\"><TD bgcolor="#FBB9AC"><A NAME="ex44"><B>EXERCISE 44:</B><BR>(link to <A HREF="answers1/answer44.html">the answer</A>)<TR><TD><TD> In Central American legend, a sorceror can transform himself
212
into a <I> nagual</I>, a familiar such as a spider-monkey; indeed, each
213
individual has an animal self or <I> wayhel</I>, living in a volcanic land
214
over which the king, as a jaguar, rules. Turn the player into his
218
<P><TR><TD Valign="top"><IMG SRC="icons/ddexercise.gif" ALT="??/\/\"><TD bgcolor="#FBB9AC"><A NAME="ex45"><B>EXERCISE 45:</B><BR>(link to <A HREF="answers1/answer45.html">the answer</A>)<TR><TD><TD> Write an <TT>orders</TT> routine for a Giant with a conscience,
219
who will refuse to attack a mouse, but so that a player who becomes
220
the Giant can be as cruel as he likes.
224
The player is still alive for as long as the variable <TT>deadflag</TT> is zero.
225
When set to 1, the player dies; when set to 2, the player wins; and all higher
226
values are taken as more exotic forms of death. Now Inform does not know
227
what to call these exotica: so if they should arise, it calls the
228
<TT>DeathMessage</TT> routine, which is expected to look at <TT>deadflag</TT> and
229
can then print something like "You have changed''.
232
Many games allow reincarnation (or, as David M. Baggett points out, in
234
You too can allow this, by providing an <TT>AfterLife</TT>.
235
This routine gets the chance to do as it pleases before any "You are
236
dead'' type message appears, including resetting <TT>deadflag</TT> back to 0 --
237
which causes the game to proceed in the normal way, rather than end.
238
<TT>AfterLife</TT> routines can be tricky to write, though, because the game
239
has to be set to a state which convincingly reflects what has happened.
242
<P><TR><TD Valign="top"><IMG SRC="icons/refs.gif" ALT="*"><TD bgcolor="#EEEEEE"><B>REFERENCES:</B><BR><SMALL>
243
The magic words "xyzzy'' and "plugh'' in 'Advent' make use of
246
'Advent' has an amusing <TT>AfterLife</TT> routine: for instance,
247
try collapsing the bridge by leading the bear across, then returning
248
to the scene after resurrection. 'Balances' has one which only
249
slightly penalises death.
255
<HR><A HREF="contents.html">Contents</A> / <A HREF="section18.html">Back</A> / <A HREF="section20.html">Forward</A> <BR>
256
<A HREF="chapter1.html">Chapter I</A> / <A HREF="chapter2.html">Chapter II</A> / <A HREF="chapter3.html">Chapter III</A> / <A HREF="chapter4.html">Chapter IV</A> / <A HREF="chapter5.html">Chapter V</A> / <A HREF="chapter6.html">Chapter VI</A> / <A HREF="chapterA.html">Appendix</A><HR><SMALL><I>Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright © Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>