How do you make a link disappear after clicking it?

Hi, I’ve been struggling with this for a very long time. I want my character to search a room but I would like for that link to disappear after clicking it.

For example:
Inspect bathroom
Inspect underneath bed
Inspect in drawer

I don’t understand how to do the “set” and “if” conditions.

I don’t know if this is real or I’m confusing all the different things I’ve read, but isn’t there some flavor of Twine that has a “choicelist” markup style - like <<choicelist: [[link]] [[link2]] [[link3]]>> that puts them in a bulleted list and vanishes them after choosing?

As you didn’t supply a code example of what each of your links is currently doing it is difficult to know if they are:

  1. redirecting the Reader to another Passage, which then redirects the Reader back to the current one.
    eg. a markup based like [[Inspect bathroom]]
  2. dynamically updating the contents of the current page without the need for a Passage Transition.
    eg. a macro based like (link: "Inspect bathroom")[...code to change the current page...]

And the solution to your problem is different in each of the above use-cases.

If you sending the Reader to an interim Passage when they select one of the links then you can use the fact that that interim Passage has now been “visited” to determine if the related link should be shown.

The (visited:) macro combined with (unless:) macro to conditionally show content, like a link.
(untested example)

(unless: (visited: "Inspect bathroom"))[ [[Inspect bathroom]]]
(unless: (visited: "Inspect underneath bed"))[ [[Inspect underneath bed]]]
(unless: (visited: "Inspect in drawer"))[ [[Inspect in drawer]]]
1 Like

If you just want text to appear in the same passage you could do it with a link:

(link: “Inspect bathroom”)[You searched the bathroom but nothing came of it.]

The link “Inspect bathroom” will dissapear.
If you want the text “Inspect bathroom” to remain but the link to dissapear you could use:

(link-reveal: “Inspect bathroom”)[: You searched the bathroom but nothing came of it.]

If you want to “enter” the bathroom (another passage) and then come back to the main passage (whch had the links to search) you could use the “set” and “if” like this:

(if: $searchBath is true)[ ]
(link: “Inspect bathroom”)[
(set: $searchBath to true)
(goto: “Bathroom”)]

So when you enter the link to the bathroom $searchBath becomes true, and when you return from the bathroom to this main passage (which had the links) no link will show.

Hope that helps

1 Like

There are two issues with the above example code:

1: Ideally you shouldn’t use is true (or is false) when evaluating the current state of a Boolean variables, as it just adds an additional step to the evaluation process to arrive at the same outcome.

The following are examples of how to conditionally do something based on the current state of a Boolean…

<!-- When the variable's value is true -->
(set: $variable to true)

(if: $variable)[...the current state of the variable is true...]

<!-- When the variable's value is false -->
(set: $variable to false)

(if: not $variable)[...the current state of the variable is false...]
(unless: $variable)[...the current state of the variable is false...]

2: Ideally you never include a conditional check in an (if:) structure that results in an empty Hook being the outcome, as it just causes an additional evaluation to be done that shouldn’t be needed if the other conditions in the structure are crafted correctly.
eg. the (if: $searchBath is true)[ ] in the above,

3: The (link-reveal-goto: ) is the better macro to use if you want to create what’s commonly known as a “Link with Setter” or a “Setter Link”, as it results in less macros calls been needed to achieve the same outcome.

note: If the Hook associated with the link contains conditional code to determine which Passage to transition to then a (link:) plus (go-to:) macro(s) combination is the better option.

Taking the above points into consideration the above code example should look something like…

(if: not $searchBath)[
    (link-reveal-goto: "Inspect bathroom", "Bathroom")[
        (set: $searchBath to true)

warning: When including code examples in a comment it is better to use the </> Code Block option instead of the Block Quote option. Because the later replaces Standard quotes (like ’ and ") with Typographical (curvy) quotes (like ‘, ’, “, ”), which causes String literals in the code (like "This is a String") to become invalid.

1 Like