0 votes
by (120 points)
retagged by
I used the linkappend macro for SugarCube v2 to create links that would append text. However, they would be undone if the reader moves to another passage and back to that same passage. How can I keep the text there after it is clicked?

1 Answer

0 votes
by (159k points)

An example of your existing code would help us know exactly how you are currently using the <<linkappend>> macros in your Passage, but I will assume its something like the following.

Some long text...

<<linkreplace "Choice 1">>Long replacement text for choice 1...<</linkreplace>>

<<linkreplace "Choice 2">>Long replacement text for choice 2...<</linkreplace>>

<<linkreplace "Choice 3">>Long replacement text for choice 3...<</linkreplace>>

[[Continue|Other]]


You will need to use story variables to track which link(s) were selected, and then use the current value of the same story varaibles to control what is displayed next time the Passage is visited.

1. Initialise your story variables within your project's StoryInit special passage.

<<set $choice1 to false>>
<<set $choice2 to false>>
<<set $choice3 to false>>

(note: the above variables can be named whatever makes sense to you and your project.)

2. Update the Passage to check the current value of the story variables.

If your actual code looks something like my 1st example and you want to keep using the <<linkreplace>> macro to reveal the hidden text then you could do somthing like the following.

Some long text...

<<if $choice1>>
	\Long replacement text for choice 1...
\<<else>>
	\<<linkreplace "Choice 1">>Long replacement text for choice 1...<<set $choice1 to true>><</linkreplace>>
\<</if>>

<<if $choice2>>
	\Long replacement text for choice 2...
\<<else>>
	\<<linkreplace "Choice 2">>Long replacement text for choice 2...<<set $choice2 to true>><</linkreplace>>
\<</if>>

<<if $choice3>>
	\Long replacement text for choice 3...
\<<else>>
	\<<linkreplace "Choice 3">>Long replacement text for choice 3...<<set $choice3 to true>><</linkreplace>>
\<</if>>

[[Continue|Other]]

... on the other hand if your actual code is different to my 1st example and you want help converting it then you will need to supply an example of it.

by (120 points)

I used <<linkappend>> like this:

<<linkappend "add text after this">> text to be added. <</linkappend>>

I also used it iteratively to create this "add-on" effect:

<<linkappend "add text after this">> text added. <<linkappend "add text again">> text added again. <</linkappend>><</linkappend>>

However the text would "un-append" themselves when I move to another passage and back again.

I tried using your method and it seemed to work even if I didn't initialize variables in a StoryInit passage. When I mean "work", I mean that the text remained there even after moving to another passage and back again. In this case, what is the purpose of initializing the variables?

Is it possible for me to achieve this effect with <<linkappend>> instead of <<linkreplace>> as it is more suited to the effect I intend to achieve?

Thanks!

...