Interactive Fiction_8 – NPC

Non Player Characters
Interacting with in game characters can be very hard!  But here are a few  very introductory tips:

If the player attacks someone or something the game will respond with “Violence isn’t the answer…”.  You can use an instead rule to work around this.

Here is how we do this:
Instead of attacking Jeff:
say “you have been suspended from school for violent behavior.”;
end the game saying “And you have failed to recover your binder.”
Right now, as our story works, the reader can type “Give the coin to Jeff,” and all will go well.  However, if the reader types, “Give the coin to the boy,” the story fails to recognize the word “boy.”
To create a synonym for Jeff, we would add the following line to Jeff’s description:
    Understand “boy” as Jeff.
Instead of asking Jeff about “the key”:
say “It’s the key to the filing cabinet.”;

What if the player doesn’t use the word “the” in their question?  We could include another instead rule.

Instead of asking Jeff about “key”:
say “It’s the key to the filing cabinet.”;
To get Jeff to give the key to the player, if asked, we could add:
Instead of asking Jeff for the key:
        say “Now you have the key.”;
        move the key to the player.
Or if the player wants to give the key to Jeff:
Instead of giving the key to Jeff:
    say “Now Jeff has the key.”;
    move the key to Jeff.
** If you would like to have more conversation built into your IF go to page 158 of this resource: Jim Aikin’s Handbook
Giving to NPC
The restaurant is a room.
The customer is a person in the restaurant.
The meal is in the restaurant.  The meal is edible.

Instead of giving the meal to the customer:
    say “You give the customer the meal.”;
    now the customer carries the meal.

**Note: Order matters, the the rule is written: “Instead of giving the customer the meal:” will not work.  **

Value is a quality, or “property,” that changes.
  For example, a filing cabinet could be closed and locked, but, later, it becomes unlocked and open.  We don’t have to do anything special to set up these values because Inform already knows about closed and locked containers.
However, we can set up our own values or variables.
We can set up a value called “mood.”  We can add that mood applies to people.  And we can set up as many moods as we want.  For now, let’s settle for “unhappy” and “pleased.”  Let’s set Jeff’s opening mood as “unhappy.”
Here’s the source code we should add:
Mood is a kind of value. The moods are unhappy and pleased. 
People have mood. The mood of Jeff is unhappy.
What can we do with values?  Actually, values are extremely powerful, and we can do a great deal with them.
Let’s start by including Jeff’s mood in his description, changing the description to read as follows:
Jeff is man in the classroom. 
The description of Jeff is “A sixth grader, wearing a baseball shirt. [if the key is carried by Jeff] He is carrying a key [end if]. Jeff looks [the mood of Jeff].”
Now, let’s invent a way to change Jeff’s mood.  Suppose that we want the player to bribe Jeff in order to get the key from him. 
We can use this source code to create a coin that the player can use as a bribe:
The coin is a thing. The player carries the coin. 
The description of the coin is “A typical piece of currency– worth something to most people.”.
Now, let’s create an instead rule that allows the player to change Jeff’s mood by giving him the coin. 
Here’s the source code:  
Instead of giving the coin to Jeff:
move the coin to Jeff;
now Jeff is pleased;
 say “Jeff looks very pleased.”.
Next, let’s create an instead rule that forces the player to change Jeff’s mood before the key can change hands.  

The source code follows, but it’s a little complicated:
Instead of asking Jeff for the key:
if Jeff is unhappy:
say “Jeff refuses to give the key, but points to the coin you’re carrying.”;
if Jeff is pleased:
say “Now you have the key.”;
move the key to the player.
** Note: In the source code that appears above, indenting is important.  All of the important indents require that the writer use the “Tab” key, not just a series of spaces.

The primary source for this page is from the XVII section of this resource:

Leave A Reply

Your email address will not be published. Required fields are marked *