Why does Inform 7 ignore my if conditions?

0 votes
57 views
asked Mar 24 in Authoring by Juhana (246 points)
recategorized Mar 27 by Alex

I have the following rule in Inform 7 that always prints both messages. It also prints the messages no matter the player takes, even if it's not the vial. It's as if the conditions are always true even though they're mutually contradictory. Why? It works when I have the conditions inside the say phrases.

Lab is a room. A vial is in the lab. A solution is in the vial.

After taking [the vial]:
    [if the solution is in the vial] say "You take the vial carefully avoiding spilling the contents."; [end if]
    [if the vial is empty] say "You take the empty vial."; [end if]

1 Answer

+1 vote
answered Mar 24 by Juhana (246 points)

There are two places where you'd use square brackets, and their meaning is different depending on where you do. Inside strings square brackets mean text substitutions or command phrases (like "if"). Everywhere else they denote comments that are completely ignored by the compiler. You should never use square brackets outside strings unless you're writing a comment.

Because the compiler ignores the comments, the code is exactly equal to:

After taking:
    say "You take the vial carefully avoiding spilling the contents.";
    say "You take the empty vial."; 

You can fix it by removing the square brackets which makes the full code visible to the compiler.

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