Need Help!

Hey guys,
im new in this Forum and i need your help.
I just wanna make a Ghost in Inform 7 wich waits infront of a door and follows me after we were in the same room (corridor).
But if i go in a special room the Ghost has to disappear and will spawn on his old place.

Hope its “understandable” my english isnt the best in the world. :smiley:

Here’s a try:

[code]The hall is a room. “The dining room is to the north.” The dining room is north of hall. “The hall is to the south and the kitchen is to the west.” The kitchen is west of dining room. “The dining room is to the east.” The servant’s door is a door. The servant’s door is north of the kitchen and south of the back staircase. The description of the back staircase is “Stairs lead up.” The upper hallway is above the back staircase. “You can go down to the lower floor here, or south to the bedroom.” The bedroom is south of the upper hallway. “The hallway is to the north.”

The ghost is a person in the kitchen. The ghost can be following.

Every turn when the location [that’s the room where the player is] is the kitchen and the ghost is in the kitchen and the ghost is not following:
say “The ghost begins to dog your footsteps!”;
now the ghost is following.

Every turn when the ghost is following and the ghost is not in the location [which will ordinarily be when the player has moved]:
say “The ghost floats in.”;
now the ghost is in the location;
if the location is the bedroom: [the special room]
say “The ghost vanishes!”;
now the ghost is in the kitchen;
now the ghost is not following.
[/code]

Ha, I made an example as well:

[code]“The Lady in Grey”

The West Corridor is a room. “This is a spooky corridor. Exits lead east and west.”

The End of the Corridor is west of the West Corridor. “This is the spookiest part of the corridor. The only exit lies east.”

The East Corridor is east of the West Corridor. “This part of the corridor is less spooky. Exits lead east and west.”

The Chapel is east of the East Corridor. “You feel strangely at peace here. An exit lies west.”

The ghost is a woman in the End of the Corridor. The ghost can be fixated.

Every turn when the ghost is in the location and the ghost is not fixated (this is the ghost fixation rule):
say “The ghost seems to fixate on you!”;
now the ghost is fixated.

Every turn when the ghost is not in the location and the ghost is fixated (this is the ghost following rule):
let the direction of movement be the best route from the location of the ghost to the location of the player;
if the direction of movement is not nothing, try the ghost going the direction of movement.

Every turn when the ghost is in the Chapel (this is the ghost retethering rule):
say “The holy power of the Chapel frightens the ghost! She vanishes into a puff of grey smoke.”;
now the ghost is not fixated;
now the ghost is in the Corridor.[/code]

Hi Flowri,

Welcome to the forum! Both Matt’s and Chinkeeyong’s solutions are essentially the same and work. I just wanted to point out that Chinkeeyong named his rules, which is a good practice. Many of us (including myself) don’t bother to do that here because we’re just kicking out example code. But when writing an actual project (game or extension) in I7, always name your rules. It makes debugging way easier.

One other friendly piece of advice: when posting a new topic, make your subject line specific. “Need Help!” doesn’t tell us anything. “How to make a following NPC” is better. It helps you because forum members who know how to do that are more likely to notice and respond. It helps the community because current and future members will have the same question and a specific subject line will make it easier for them to find the answer via search.

Happy Halloween,

okay thank you guys so much :slight_smile:

it’s quite easy when you know how to write it, isn’t it?

i got 2 more problems can i write it down here? :smiley:

I don’t see any reason why not.

You might want to make separate threads for them, so you can give them specific subject lines. But please do post them!

i have to say that you guys are pretty awesome.

How can i create a Tic Tac Toe game against the computer? and when i win a door or something opens?
And
ehm what does it called. Intercom? or something like that on a door where u can speak or comunnicate with a NPC?

For tic-tac-toe, the main difficulty will be writing the algorithm. But that isn’t Inform-specific. As far as the Inform part goes, I’d number the cells 1 to 9, and then make a new action for >PLAY 5.

Playing is an action applying to a number. Check playing a number lower than 1: say "That makes no sense." instead. Check playing a number greater than 9: say "There are only nine cells." instead.

Then have the computer react in a “carry out playing” rule.

For an intercom, the easiest way would be to make the intercom itself your NPC, with the character’s name as an alias. You could also use Inanimate Listeners by Emily Short if you want to allow >ASK and >TELL but not commands.

I had an afternoon of free time, so here’s a simple implementation of tic-tac-toe that you can adapt for your project:

[spoiler][code]“Flowri Jones and the Temple of Tic-Tac-Toe” by Chin Kee Yong

Part 1 - Setting Up the Game Board and Game Pieces

[This part creates the things in the game world that the player can actually interact with.]

There is a room called Outside the Temple. “At last, you’ve finally discovered the fabled Temple of Tic-Tac-Toe. Only one obstacle remains: the Door of Three Rows and Three Columns, which no explorer has ever managed to open.”

A door called the Door of Three Rows and Three Columns is inside from Outside the Temple. “The Door looks like this:[paragraph break][tic-tac-toe-board]”. [We define tic-tac-toe-board in Chapter 1.3.] The Door of Three is closed and locked.

Chapter 1.1 - Tic-Tac-Toe Spaces

[For this example game, we’re going to have each space on the tic-tac-toe board be a container that the player puts a nought or cross into.]

Section 1.1.1 - Defining a Tic-Tac-Toe Space

[Here we define a tic-tac-toe space and create the individual spaces. I’ve used hyphens while naming to ensure zero ambiguity, but we allow spaces and American spelling for the player’s convenience.]

A tic-tac-toe space is a kind of container.

The upper-left space is a tic-tac-toe space part of the Door of Three. Understand “upper left” as the upper-left space.
The upper-middle space is a tic-tac-toe space part of the Door of Three. Understand “upper middle” as the upper-middle space.
The upper-right space is a tic-tac-toe space part of the Door of Three. Understand “upper right” as the upper-right space.

The centre-left space is a tic-tac-toe space part of the Door of Three. Understand “center-left” or “center/centre left” as the centre-left space.
The centre space is a tic-tac-toe space part of the Door of Three. Understand “center” as the centre space.
The centre-right space is a tic-tac-toe space part of the Door of Three. Understand “center-right” or “center/centre right” as the centre-right space.

The lower-left space is a tic-tac-toe space part of the Door of Three. Understand “lower left” as the lower-left space.
The lower-middle space is a tic-tac-toe space part of the Door of Three. Understand “lower middle” as the lower-middle space.
The lower-right space is a tic-tac-toe space part of the Door of Three. Understand “lower right” as the lower-right space.

[It’s not entirely intuitive to refer to the spaces in this manner, so this example game starts with a gentle prompt for the player.]

Before reading a command while the turn count is 1 (this is the tic-tac-toe tutorial rule):
say “(To refer to the spaces on the Door, use ‘upper-left space,’ ‘upper-middle space,’ ‘upper-right space,’ ‘centre-left space,’ ‘centre space,’ and so on.)” ;

Section 1.1.2 - Defining Relations

[Now that we’ve created the boxes, we’re going to lay them out so that Inform can see their relative positioning. This is crucial because victory in tic-tac-toe relies on positioning.

We could use a matrix or a table for this, since the game board in this case is a square grid. However, I’ve chosen to take the approach of defining new relations and linking our tic-tac-toe spaces using the new relations. This approach can be extended to game boards like Chinese Checkers that are other shapes.

First we create our new positional relations and define assertion verbs for them.]

Vertical connecting relates tic-tac-toe spaces to each other.
The verb to be vertically connected to means the vertical connecting relation.

Horizontal connecting relates tic-tac-toe spaces to each other.
The verb to be horizontally connected to means the horizontal connecting relation.

Right-diagonal connecting relates tic-tac-toe spaces to each other. [This indicates spaces that can be connected with a “”]
The verb to be right-diagonally connected to means the right-diagonal connecting relation.

Left-diagonal connecting relates tic-tac-toe spaces to each other. [This indicates spaces that can be connected with a “/”]
The verb to be left-diagonally connected to means the left-diagonal connecting relation.

Section 1.1.3 - Assigning Positional Relations to the Spaces

[Now we lay out the pieces. We systematically do this running from upper-left to upper-right, then centre-left to centre-right, then lower-left to lower-right. Since our relations go both ways, we don’t have to define the reversed relations.]

The upper-left space is horizontally connected to the upper-middle space, vertically connected to the centre-left space, and right-diagonally connected to the centre space.
The upper-middle space is horizontally connected to the upper-right space, left-diagonally connected to the centre-left space, vertically connected to the centre space, and right-diagonally connected to the centre-right space.
The upper-right space is left-diagonally connected to the centre space and vertically connected to the centre-right space.

The centre-left space is horizontally connected to the centre space, vertically connected to the lower-left space, and right-diagonally connected to the lower-middle space.
The centre space is horizontally connected to the centre-right space, left-diagonally connected to the lower-left space, vertically connected to the lower-middle space, and right-diagonally connected to the lower-right space.
The centre-right space is left-diagonally connected to the lower-middle space and vertically connected to the lower-right space.

The lower-left space is horizontally connected to the lower-middle space.
The lower-middle space is horizontally connected to the lower-right space.

[A tic-tac-toe board is small enough that we can define it by hand. If your game board is really large, you could instead write something like “A Row 1 space is a kind of thing. A Row 2 space is vertically connected to every Row 1 space. A Row 3 space is vertically connected to every Row 2 space…”]

Chapter 1.2 - Tic-Tac-Toe Pieces

[Here we define the tic-tac-toe pieces and place them in the game world. The player takes the noughts, while the computer takes the crosses.]

A tic-tac-toe piece is a kind of thing.

A nought is a kind of tic-tac-toe piece. Understand “O” or “circle” as a nought.

A cross is a kind of tic-tac-toe piece. Understand “X” as a cross.

Five noughts are in Outside the Temple. There are five crosses. [The crosses are off-stage.]

Chapter 1.3 - Displaying the Tic-Tac-Toe Board

[We create a phrase to say the current state of the tic-tac-toe board. This is used in the initial appearance of the Door of Three Rows and Three Columns, as described at the beginning of this Part 1. Later, we also use it to show the player how the board changes after each move that is made.

First, we create a phrase that translates the current state of a tic-tac-toe space into “X”, “O”, or a space:]

To say shorthand of (current space - a tic-tac-toe space):
if there is nothing in the current space:
say " ";
otherwise if there is a nought in the current space:
say “O”;
otherwise if there is a cross in the current space:
say “X”;
otherwise:
say “?”.

[Then we draw a simple representation of the board using a fixed-width font.]

To say tic-tac-toe-board:
say fixed letter spacing;
say " [shorthand of the upper-left space] | [shorthand of the upper-middle space] | [shorthand of the upper-right space] ";
say line break;
say “—±–±--”;
say line break;
say " [shorthand of the centre-left space] | [shorthand of the centre space] | [shorthand of the centre-right space] ";
say line break;
say “—±–±--”;
say line break;
say " [shorthand of the lower-left space] | [shorthand of the lower-middle space] | [shorthand of the lower-right space] ";
say variable letter spacing.

Part 2 - Checking for Victory

[This part defines the conditions ‘if X will win for noughts’ and ‘if X will win for crosses,’ which each check whether choosing a space will result in victory for the appropriate side. These conditions are checked in Part 3, the tic-tac-toe playing algorithm, and Part 4, which enforces the rules of tic-tac-toe.

There are two possible scenarios in which placing a piece into a space will result in victory:
A) Given an axis, there are two adjacent spaces on that axis which both contain pieces of the same kind.
B) Given an axis, there is an adjacent space which contains a piece of the same kind, and that space also has an adjacent space which contains a piece of the same kind.

If either of these scenarios is met, the condition is true. Otherwise, the condition is false.]

To decide whether (checked space - a tic-tac-toe space) will win for noughts:
[Run through possible cases of Scenario A]
if two tic-tac-toe spaces containing a nought are vertically connected to the checked space, decide yes;
if two tic-tac-toe spaces containing a nought are horizontally connected to the checked space, decide yes;
if two tic-tac-toe spaces containing a nought are right-diagonally connected to the checked space, decide yes;
if two tic-tac-toe spaces containing a nought are left-diagonally connected to the checked space, decide yes;
[Run through possible cases of Scenario B]
if the checked space is vertically connected to a tic-tac-toe space (called the connecting space):
if the connecting space contains a nought and the connecting space is vertically connected to a tic-tac-toe space (called the far space) that is not the checked space:
if the far space contains a nought, decide yes;
if the checked space is horizontally connected to a tic-tac-toe space (called the connecting space):
if the connecting space contains a nought and the connecting space is horizontally connected to a tic-tac-toe space (called the far space) that is not the checked space:
if the far space contains a nought, decide yes;
if the checked space is right-diagonally connected to a tic-tac-toe space (called the connecting space):
if the connecting space contains a nought and the connecting space is right-diagonally connected to a tic-tac-toe space (called the far space) that is not the checked space:
if the far space contains a nought, decide yes;
if the checked space is left-diagonally connected to a tic-tac-toe space (called the connecting space):
if the connecting space contains a nought and the connecting space is left-diagonally connected to a tic-tac-toe space (called the far space) that is not the checked space:
if the far space contains a nought, decide yes;
[Neither scenario is true]
decide no.

To decide whether (checked space - a tic-tac-toe space) will win for crosses:
[Run through possible cases of Scenario A]
if two tic-tac-toe spaces containing a cross are vertically connected to the checked space, decide yes;
if two tic-tac-toe spaces containing a cross are horizontally connected to the checked space, decide yes;
if two tic-tac-toe spaces containing a cross are right-diagonally connected to the checked space, decide yes;
if two tic-tac-toe spaces containing a cross are left-diagonally connected to the checked space, decide yes;
[Run through possible cases of Scenario B]
if the checked space is vertically connected to a tic-tac-toe space (called the connecting space):
if the connecting space contains a cross and the connecting space is vertically connected to a tic-tac-toe space (called the far space) that is not the checked space:
if the far space contains a cross, decide yes;
if the checked space is horizontally connected to a tic-tac-toe space (called the connecting space):
if the connecting space contains a cross and the connecting space is horizontally connected to a tic-tac-toe space (called the far space) that is not the checked space:
if the far space contains a cross, decide yes;
if the checked space is right-diagonally connected to a tic-tac-toe space (called the connecting space):
if the connecting space contains a cross and the connecting space is right-diagonally connected to a tic-tac-toe space (called the far space) that is not the checked space:
if the far space contains a cross, decide yes;
if the checked space is left-diagonally connected to a tic-tac-toe space (called the connecting space):
if the connecting space contains a cross and the connecting space is left-diagonally connected to a tic-tac-toe space (called the far space) that is not the checked space:
if the far space contains a cross, decide yes;
[Neither scenario is true]
decide no.

Part 3 - The Tic-Tac-Toe Playing AIgorithm

[This part defines the algorithm which the computer uses to determine its next move. While it is possible to create an algorithm that will never lose, we want the player to be able to defeat the computer, and so we’ll create one that is imperfect while still posing a challenge.

Our algorithm will be in the form of a rulebook which the computer consults. The rulebook will decide on one of the tic-tac-toe spaces and pass it back to the computer, which will translate that into a move within the game. Right now our rulebook is very simple, but it can be expanded to create more complex behavior for the computer.]

The tic-tac-toe playing rules are a rulebook producing a tic-tac-toe space.

Chapter 3.1 - The Check for Legal Moves Rule

[Rule #0: If there are no empty spaces, do nothing. It shouldn’t be possible for the rulebook to be consulted when there are no empty spaces, but you never know when bugs will pop up.]

A tic-tac-toe playing rule (this is the check for legal moves rule):
if none of the tic-tac-toe spaces contain nothing, rule fails.

Chapter 3.2 - The Play to Win Rule

[Rule #1: If placing an X in a space results in the computer getting three in a row, choose that space to win.]

A tic-tac-toe playing rule (this is the play to win rule):
repeat with considered space running through tic-tac-toe spaces that contain nothing:
if the considered space will win for crosses, rule succeeds with result the considered space.

Chapter 3.3 - The Play to Not Lose Rule

[Rule #2: If placing an O in a space results in the player getting three in a row, choose that space to block the player’s victory.]

A tic-tac-toe playing rule (this is the play to not lose rule):
repeat with considered space running through tic-tac-toe spaces that contain nothing:
if the considered space will win for noughts, rule succeeds with result the considered space.

Chapter 3.4 - The Play at Random Rule

[Rule #4: If no result is obtained so far, choose a space at random.]

A tic-tac-toe playing rule (this is the play at random rule):
rule succeeds with result a random tic-tac-toe space that contains nothing.

Part 4 - Enforcing The Rules of Tic-Tac-Toe

[This part enforces the rules of tic-tac-toe within the game world.]

Chapter 4.1 - Interacting with the Game Board

[Here we block actions that interfere with the rules of tic-tac-toe, such as attempting to put more than one piece into a space or attempting to take a piece out of a space.]

Check taking something when the noun is in a tic-tac-toe space (this is the can’t take things from tic-tac-toe spaces rule):
say “An unseen force prevents you from taking [the noun].” instead.
Check inserting something that is not a tic-tac-toe piece into a tic-tac-toe space (this is the can’t put random junk into a tic-tac-toe space rule):
say “An unseen force prevents you from inserting [the noun] into [the second noun].” instead.
Check inserting something into a tic-tac-toe space when the second noun contains something (this is the can’t put things into filled tic-tac-toe spaces rule):
say “[The second noun] already contains [a random thing in the second noun].” instead.

Chapter 4.2 - The Player’s Move

[When the player inserts a piece into a space, that is counted as the player’s move in the tic-tac-toe game. We show the new state of the tic-tac-toe board, then check whether it’s a winning move. If it isn’t, the computer makes its move, and we check whether that’s a winning move for the computer. Next, we reset the board if all the spaces have been filled.]

After inserting a nought into a tic-tac-toe space when the Door of Three is locked (this is the tic-tac-toe move rule):
say “[The noun] slots into [the second noun]. The Door now looks like this:[paragraph break]”;
say tic-tac-toe-board;
say paragraph break;
if the second noun will win for noughts:
now the Door of Three is unlocked;
now the Door of Three is open;
say “You are victorious! With a reluctant groan, the Door of Three Rows and Three Columns swings open…”;
end the story finally;
otherwise if a cross is nowhere and a tic-tac-toe space contains nothing:
let the computer’s chosen space be the tic-tac-toe space produced by the tic-tac-toe playing rules;
if the computer’s chosen space is a tic-tac-toe space:
now a random off-stage cross is in the computer’s chosen space;
say “A cross appears from thin air and slots into [the computer’s chosen space]. The Door now looks like this:[paragraph break]”;
say tic-tac-toe-board;
say paragraph break;
if the computer’s chosen space will win for crosses:
now all the noughts are in Outside the Temple;
now all the crosses are nowhere;
say “You have been defeated! Mocking laughter echoes through the air as the noughts tumble around you… The Door now looks like this:[paragraph break]”;
say tic-tac-toe-board;
say paragraph break;
if all the tic-tac-toe spaces contain something:
now all the noughts are in Outside the Temple;
now all the crosses are nowhere;
say “The game has ended in a tie! The door shudders and the noughts tumble around you… The Door now looks like this:[paragraph break]”;
say tic-tac-toe-board;
say paragraph break.[/code][/spoiler]

1 Like

+1 chin keeyong, that is above and beyond!

chinkeeyong this is abolutely awesome… i thank you so much…<3

The Inform recipe book has a nice section on telephones. It mentions microphones, which should take care of your intercom challenge.