Login
Remember
IF Answers
Ask a Question

# 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.

- inform7
- programming
- follow
- player

## 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.

## Related questions

- Copying the location of a thing to a variable when it's in something other than a room.
- How to make a thing that can be seen from every room?
- What are the exact details and relations concerning the player, yourself, and your former self in Inform 7?
- Is there a maximum rules limit in Inform 6?
- Is there a way to reduce the right margin for a play-in-browser website released by Inform 7?

...