I’m trying to set up a condition and Inform 7 isn’t being helpful.

I want to set up the condition that if the player and a ghost are in the same room for two consecutive turns, the player dies. But Inform doesn’t understand the following:

If player and ghost are in the same location for 2 turns, the game ends.

Inform prints the message:

Problem. You wrote ‘If player and ghost are in same location for 2 turns, the game ends’ , but also ‘If player and ghost are in same location for 2 turns, the game ends’ : that seems to be saying that the same object (If player) must be in two different places (same location for 2 turns and game ends). This looks like a contradiction.

This sometimes happens as a result of a sentence like ‘Every person carries a bag’, when Inform doesn’t know ‘bag’ as the name of any kind - so that it makes only a single thing called ‘bag’, and then the sentence looks as if it says everyone is carrying the same bag.

I’m trying to figure out what I did wrong. The message makes no sense to me.

Inform doesn’t generally understand “same”. Since “the location” on its own means the location of the player, you can do something like this:

The ghost counter is initially zero.
Every turn:
    if the ghost counter is two:
        end the story saying "You have died.";
    otherwise if the ghost is in the location:
        increment the ghost counter;
        now the ghost counter is zero.

The “ghost counter” variable counts how many turns the player has spent in the ghost’s presence. If it hits 2, the game ends.

It compiles!
Thanks so much!

Just to explain why the original message made no sense: Instead of parsing the line as an if-then, Inform decided that the main verb was “are in.” So it thought that you were trying to create a thing called “if player” and maybe another thing called “ghost” and then declare them as being in a container called “same location for 2 turns.” And maybe another one called “game ends”?

I’m not quite sure of the exact parsing, but it’s pretty common when you have a syntax error that Inform will grab hold of the wrong bit of the line and give you an error based on that, even if it looks ridiculous–we know that it’s supposed to be a conditional, but Inform doesn’t know that we don’t want to define something called “if player.” (Who knows, maybe it’s something that plays IF.) When you get a totally incomprehensible error message like this it’s a good idea to just pretend it says SYNTAX ERROR.