Login
Remember
IF Answers
Ask a Question

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

- inform7

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

## Related questions

- Why aren't "if" and "otherwise" doing what I expected in Inform 7?
- How does punctuation work in Inform 7 code?
- How do I change 'if the player consents'? pre-Inform 6L or post-
- [Inform 7]Timers, daemons, switchon & switchoff
- [Inform 7] How to implement a blanket 'not understood' comment for an Inanimate Listener

...