0 votes
by (160 points)

I'm trying to have a series of toggles on my the first page of my story for the user to adjust settings. What I want is for the page to display e.g. 'Off' as a link that the user can click to toggle the setting on, and have the same passage reload displaying 'On' (which can then be clicked to toggle back off). The following throws an error ('RangeError: Maximum call stack size exceeded at _toConsumableArray at Object.run...'):

(if: $blurb is true)[(link: "Off")[(set:$blurb to false)(go-to:"Main")]]
(else: )[(link: "On")[(set:$blurb to true)(go-to:"Main")]]

I'm new at twine so apologies if I'm missing something obvious with the syntax, but I tried several variations on the above and keep getting the same error.

1 Answer

+1 vote
by (159k points)

You don't need to re-direct the Reader back to the current Passage to dynamically update a toggle like link, the following example shows how to use a named hook combined with the (replace:) and  (display:) macros to achieve that effect.

1. Place something like the following within the Passage you want to see the toggle in.

(set: $blurb to false)

Turn the blurb |blurb>[(display: "Blurb")]

2. Place the conditional link replaced code in a child Passage named Blurb

{
(if: $blurb)[
	(link: "Off")[
		(set: $blurb to false)
		(replace: ?blurb)[(display: "Blurb")]
	]
]
(else:)[
	(link: "On")[
		(set: $blurb to true)
		(replace: ?blurb)[(display: "Blurb")]
	]
]
}

 

by (160 points)
That's perfect, thank you so much.
...