Can I hide a link if a passage has a certain tag?

Twine Version: 2.8.1

Hi folks

I have a fight system that “travels” through various passages depending on the outcome of certain variables. These passages have the tag “Fight”.

I also have a basic inventory system that displays an item if $HasItemName is true. One of those items is a potion that, in the normal inventory, displays like so:

(if: $HasGreenPotion is true)[A vial containing a green liquid which you may [[drink->GreenPotionDrink]]]

When the player is taking part in a fight (ie in a passage that has the tag “Fight”) I want the item to display in the inventory but not include the option to drink it.

In my head, I’m after something that says

(if: $HasGreenPotion is true and tag is "Fight")[A vial containing a green liquid]

but I can’t find a way to reference the tag.

Am I missing something simple? :slight_smile:

You can access tags through the (passage:) macro.

https://twine2.neocities.org/#macro_passage

(if: (passage:)'s tags contains "Fight")[
  (set: _isFight to true)
](else:)[
  (set: _isFight to false)
]

I suggest using a temporary variable with the _ character so that it only exists in the current passage. We see if the tags property of the curent passage’s datamap contains the word “Fight” because it’s an array. There can be multiple tags associated with a passage.

A better way might be to assume the passage is not a fight until we check for it. Plus, it’s less code. Less code equals “more readable” in most cases.

(set: _isFight to false)
(if: (passage:)'s tags contains "Fight")[
  (set: _isFight to true)
]

I haven’t tested this, but I think the logic is sound. I hope this helps.

Let us know if you have any other questions.

> (if: (passage:)'s tags contains "Fight")[
>   (set: _isFight to true)
> ](else:)[
>   (set: _isFight to false)
> ]

Thanks - this works a treat. I’ve incorporated the variable in my Inventory passage (which I should have mentioned is its own passage as a footer) and then run some tests on other passages marked with the Fight tag and the potion is drinkable when not in a fight, and appears as a simple piece of text during a fight.

Thanks again.

1 Like