[Sugarcube2 ] Appending multiple links within each other + multiple clicks before link triggers

Hello! I’m completely new to Twine and trying to figure out macros.

Twine 2.9
Sugarcube 2.36.1

Is it possible to nest <<link append>> functions within each other? What I mean by that is, take the following:

He was startled awake by the sound of his phone alarm. The harsh tone blared as he fumbled to turn it off.

When you click on "fumbled to turn it off, I want that link to deactivate, and then append the following:

After a few tries, he managed to stop the alarm. He squinted at the time.

“Hnng…is it seven already…?”

I want “Hnng…is it seven already…?” to also be another link that appends more information into the same passage.

How can this be accomplished? I run into issues with <<link append>> since it does not seem to nest.

Thank you for the help.

You can absolutely nest <<linkappend>>:

He was startled awake by the sound of his phone alarm. The harsh tone blared as <<linkappend 'he fumbled to turn it off.'>>

After a few tries, he managed to stop the alarm. He squinted at the time.

<<linkappend '"Hnng…is it seven already…?"'>>

More text here.<</linkappend>><</linkappend>>

Nesting a lot of them can get unwieldy, though. Another thing you can do is break up the text into various passages and use the <<include>> macro:

:: passage1
He was startled awake by the sound of his phone alarm. The harsh tone blared as <<linkappend 'he fumbled to turn it off.'>>

<<include passage2>><</linkappend>>


:: passage2
After a few tries, he managed to stop the alarm. He squinted at the time.

<<linkappend '"Hnng…is it seven already…?"'>>

<<include passage3>>
<</linkappend>>
4 Likes

Thank you so much. :smiling_face_with_three_hearts: That worked. I am unfamiliar with how the macros work so that was really helpful. I actually tried doing it manually via jquery, which was actually insane.

This is a related question, but do you know if there’s a macro that would make it so I have to click X number of times before the link append triggers?

There’s no macro to do that, but you can do something like this:

<<set _i = 0>>

<span class="foo">
  <<link "Click this three times.">>
    <<set _i++>>
    <<if _i >= 3>>
      <<replace .foo>>
        Click this three times.
        
        More text.
      <</replace>>
    <</if>>
  <</link>>
</span>

That said, I’d recommend against doing this. If I’m playing a game and nothing happens when I click a link, I’m probably going to assume it’s a bug and close the game. I don’t doubt that others would do the same.

1 Like

I actually intended on triggering some kind of visual response until the third click. I haven’t figured out how to do that kind of thing, but for example, the link shifts visually to the right.

I see what you mean though. It would be misleading without an obvious interaction response that signals you should keep clicking.

Our if curiosity, can you also nest <<linkreplace>>? I assume it works the same as append?

Thanks again.

You can nest <<linkreplace>>, yes.