0 votes
by (1.3k points)

Hi all,

I want to make something happen if and only if two tags are present in a passage. This is ideally what it would look like:

(if: (passage: )'s tags contains "TagA" and "TagB")[
(print: "yes the passage has both tags")](else:)[
(print: "the passage may have one or the other tag, but not both")]

But I think this makes Twine try to add the two tags together. I can do this:

(if: (passage: )'s tags contains "TagA")[
(if: (passage: )'s tags contains "TagB")[
(print: "yes both tags")] 
]

But this gets clunky over time...

Any thoughts? 

Twine 2, Harlowe 1.2.4

1 Answer

0 votes
by (61.7k points)
edited by
 
Best answer

Try this: 

(if: ((passage:)'s tags contains "TagA") and ((passage:)'s tags contains "TagB"))[...

Explanation

The "and" operator joins two expressions together, however, these expressions need to both be complete. Having a complete expression is sort of like having a complete sentence: in a sentence you need to have all the parts, a subject and a predicate. In an expression, you need an operator, and a number of values (usually two, but sometimes one or three) to operate on based on what that operator is. In your first example, you have one complete expression, and then an "and", and then a value with no operator. In an (if:) the expression is a comparison, and each expression is being evaluated for whether it is true or false. So your expression get evaluated like this: 

IF: 
  The passage's tags contains 'TagA' is true. 
AND IF: 
  'TagB' is true. 
THEN: 
  Do this hook. 

The second instruction isn't complete, and doesn't make sense. It can't really be evaluated. 

Note: 

In Harlowe 2, the parser will attempt to figure out what you mean, but don't rely on it. Always use complete expressions. 

Edit. Forgot a "contains" in the example. 

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...