Add the gifts of motion and conversation to your characters.
Adding NPCs to your Inform adventures ( [Hack #88] ) can make your game come alive. Of course, the more vivacious your characters, the better the illusion of reality. What’s missing is movement and speech.
Let’s add another nonplayer character with a bit more zip than our sedentary access controller; how about a fearsome security daemon to smack our little spy around? Since you’ve already cast a shrieking beast as the access controller, let’s go another direction with the security daemon:
Object pixie "security daemon"
with name 'security' 'daemon' 'pixie' 'melodious' 'chimes' 'gossamer'
'wings',
describe
"^A security daemon is here, buzzing angrily around you.",
description
"The tiny security daemon darts around on gossamer wings,
leaving a trail of melodious chimes in her wake.",
before [;
Listen: "She makes a lovely little racket as she swoops about.";
],
has animate female;Note that the player can refer to the chimes and the wings;
it’s bad form to mention something and then have the
game spit out a message saying You can't
see
any
such
thing. when the player tries to interact with it.
On the other hand, the chimes and wings aren’t
separate objects here because this encourages players to interact
with them more extensively than needed. Plus, now both
listen to chimes and listen to daemon produce the same message without any extra code.
You’ve probably also noticed the
describe line. This line prints if the player
issues a look command while the daemon is in the
room. Without it, the program prints a dull default such as
You
can
also
see
a
security
daemon here..
Right now the security daemon doesn’t live anywhere
in the game world; we’ll write some code to make her
show up when we need her. You handle this in several ways. The crude
method is to copy and paste pixie code to place
pixie1, pixie2,
pixie3, and so on in all the locations in which
she’ll appear, perhaps using
each_turn routines in each room to make her appear
and disappear as needed. This is perhaps the least elegant way
possible to move NPCs around; it’s also the method I
usually employ. Let’s try something more elegant.
Use a daemon block to move
pixie around. (Did you wonder why we
didn’t just call her daemon?
Here’s your answer.) Add the following code to the
pixie object:
number 0,
daemon [;
if (player notin Quarantine) {
self.number++;
switch (self.number) {
3: move self to location;
print "^The security daemon zips in! If you can't
think of something fast you'll be ";
if (Quarantine has visited) print "back ";
"in quarantine before you can turn around.";
4: "^With a sprightly jingling sound, the security daemon
zaps you with paralyzing bolts!";
5: self.number = 0; remove self;
print "^With a mighty zap, the security daemon
banishes you to...^";
PlayerTo(Quarantine); rtrue;
}
}
],The daemon block checks to see if the player
character is in the Quarantine room (which we’ll
implement in a moment). If not, it increments
pixie’s number
property. When that value reaches 3—giving the player a couple
of turns to poke around without interference—the security
daemon shows up. (A quickie if statement allows
for a different message if you’ve been in quarantine
before.) The player has a couple of turns to try to interact with the
security daemon before she moves him to the quarantine area.
Let’s create that area now with a few exits:
Object Quarantine "Quarantine"
has light,
with
description
"You are inside a spherical prison of glowing mesh. It seems
to have been designed with giant worms and other such monstrosities
in mind, though, because the spaces in the mesh are more than
large enough for you to pass through. Interesting-looking exits
lead north, west, and up.",
n_to Memory,
w_to CD_Burner,
u_to Graphics_Card,
cant_go "There doesn't seem to be anything interesting in that
direction.";
Object Memory "Memory Chip DIMM-2"
has light,
with
description
"(fill this in, reader!) Exits lead southwest and south.",
sw_to CD_Burner,
s_to Quarantine;
Object CD_Burner "CD Burner CDR-6"
has light,
with
description
"(fill this in, reader!) Exits lead northeast and east.",
ne_to Memory,
e_to Quarantine;
Object Graphics_Card "Graphics Card NV-144"
has light,
with
description
"(fill this in, reader!) An exit leads down.",
d_to Quarantine,
out_to Quarantine;The player character now has some room to wander around. You still
need to activate the daemon’s
daemon for the chase to be on. Attempts to leave
the wireless connection trigger the pursuit code. See the
cant_go line in the Quarantine
object? A cant_go routine runs whenever the player
attempts to go in a direction the room doesn’t
support. Usually, people use it for customized error messages, but
you can run code there as well. Put this in the
Wireless object:
cant_go [;
StartDaemon(pixie);
print "Before you can make a move, you hear a cascade of chimes
and a tiny security daemon blasts you to bits! When you
collect yourself, you find yourself in...^";
PlayerTo(Quarantine); rtrue;
],Perfect! Well, almost. The player character can still saunter out of
the room, away from the daemon, and her messages will continue to
print as if she were there. This can actually be desirable behavior
because daemon code (and timers) can be attached
to things that aren’t in the room: distant church
clocks can chime, thieves can ransack the player
character’s hotel room while he is out exploring the
city, and so forth. Here you want the security daemon to follow the
player character around instead, so insert this code before the
switch statement in the daemon
block:
if (self notin location && self.number > 3) {
move self to location;
print "^You hear a riot of tiny bells as the security
daemon swoops in after you.^";
}Let’s make sure this actually does the right thing. Here’s an excerpt from a sample transcript:
> z
Time passes.
The security daemon zips in! If you can't think of something fast you'll be
back in quarantine before you can turn around.
> sw
CD Burner CDR-6
(fill this in, reader!) Exits lead northeast and east.
You hear a riot of tiny bells as the security daemon swoops in after you.
With a sprightly jingling sound, the security daemon zaps you with
paralyzing bolts!
>Obviously, there’s a puzzle to solve to convince the pixie to stop quarantining the player. If only you could reason with the pixie ... but that’s the stuff of [Hack #90] .