Ghost that follows player, after being in specific room. Stop following when player is in other specific room.

0 votes
37 views
asked Oct 22 in Authoring by anonymous
recategorized Oct 22 by bg

Hello,
i want to program a ghost that follows the player after going to into a specific room.
For example the kitchen. The ghost then follows the player until the player reaches another specific room. For example the bathroom. After entering the bathroom the ghost vanishes and is back in the kitchen.

This is my code right now:

Ghost is a man. It is in kitchen.

Every turn:
if the location of Ghost is not the location of the player:
let the way be the best route from the location of Ghost to the location of the player, using doors;
try Ghost going the way;
if player is in bathroom:
move Geist to ktichen.

1 Answer

0 votes
answered Oct 22 by Ryan Veeder (290 points)

If you want the ghost to always be in the same room as the player (instead of approaching from across the map) then instead of using "let way be the best route..." you can just move the Ghost to wherever the player is.

"Ghost Follows Around"

Entrance is a room.

Kitchen is north of Entrance.

Bathroom is south of Entrance.

Ghost is a man in Kitchen.

Ghost can be following.

Every turn while player is in Kitchen:
    if Ghost is not following:
        say "The ghost starts following you!";
        now Ghost is following.

Every turn while Ghost is following:
    if Ghost is not in the location:
        say "The ghost follows you in!";
        now Ghost is in the location.

Every turn while player is in Bathroom:
    if ghost is following:
        say "The ghost disappears!";
        now Ghost is not following;
        now Ghost is in Kitchen.

When the ghost is "following," it just pops up in the room whenever the player moves. ("Now Ghost is in the location" means "move the ghost to the room where the player is.) We make this stop by saying that the ghost is not following anymore when the player is in the bathroom.

It's probably a good idea to include a message like "The ghost follows you in!" because otherwise the player won't know the ghost has followed her until she tries >LOOK again. Of course, when the player gets to the bathroom, two different messages will be triggered:

Entrance
The ghost follows you in!

>s

Bathroom
The ghost follows you in!

The ghost disappears!

If you don't want this to happen, you can insert the "ghost disappears" rule into the "ghost follows" rule:

Every turn while Ghost is following:
    if location is Bathroom:
        say "The ghost disappears!";
        now Ghost is not following;
        now Ghost is in Kitchen;        
    otherwise if Ghost is not in the location:
        say "The ghost follows you in!";
        now Ghost is in the location.

Now only one message will show up in either situation.

This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...