0 votes
by (160 points)

Hi all,

Apologies if this is a bit of a weird one. What I'm trying to achieve is this:

  • The player can click on certain words/sentences  ("leads") to "open" them into other words/sentences ("answers"). This bit works with (click:), (click-replace:), etc.
  • When the player leaves the passage and returns, Twine checks if any of the "leads" have been clicked on. If so, then their "answers" display, rather than making the player click on them again.

So far, opening up the leads works fine, and so does seeing this effect other passages in the game. However, when I return to the original passage, instead of showing either the "lead" or its "answer", the passage just skips it entirely. So basically, something seems to be going wrong with checking if the lead has been opened or not (a "true"/"false" statement).

 

Here is my code:

 

{
This is Test passage 1.1. 
(if: $Test111 is "false")[
[This is the lead.]<Test111Lead|
]

(if: $Test111 is "true")[
(show: ?Test111Answer)
]

(click-replace: ?Test111Lead)[(show: ?Test111Answer)]

[And this is the answer.(set: $Test111 to "true")](Test111Answer|
Another sentence goes here.
}

 

1 Answer

+1 vote
by (159k points)
selected by
 
Best answer

If you want to track if something is true or false then you should use a Boolean value instead of a String based one.

1. Initialise your story variables within a startup tagged special passage like so.

(set: $Test111 to false)


2. Use CSS within your project's Story Stylesheet area to hide the visual output of the startup tagged passage.

tw-include[type="startup"] {
	display: none;
}


WARNING: Due to how the (click:) related macro works it is generally recommend to only using them if it is not possible to achieve a similar result using a (link:) related macro.

3. Use (if:) macros and a (unless:) macro to control when the Lead and Answer are shown.

{
This is Test passage 1.1.
<br>
(unless: $Test111)[
	(link: "This is the lead")[{
		(set: $Test111 to true)
		(show: ?Test111Answer)
	}]
]
[And this is the answer.](Test111Answer|
}

(if: $Test111)[
	(show: ?Test111Answer)
]

note: A hidden hook need to be added to the HTML page before a related (show:) macro can be used to reveal it, because of this you should place the hidden hook earlier within the Passage than the related (show:) macro.
The exception to this condition is when the related (show:) macro is placed within the associated hook of an interaction macro like (link:) or (click:).

by (160 points)
Thank you so much for your help, perfect solution! And cheers for the heads-up about (link:), too!
...