0 votes
by (250 points)
I know how to set up a repeat-link that adds to a variable every time you click it:

(link-repeat: "Click")[(set:$clicks to it + 1)]

And I have implemented cycling links, so that the text in the link changes every time you click it:

(set: $weapon to "Sword")<tw-link class='cyclingLink' data-cycling-texts='["Sword", "Axe", "Harsh language"]' onclick='clickCyclingLink(this, "$weapon");'>&weapon</tw-link>

But how can I combine the two? I tested the following:

(set: $weapon to "Sword")<tw-link class='cyclingLink' data-cycling-texts='["Sword", "Axe", "Harsh language"]' onclick='clickCyclingLink(this, "$weapon");'>(link-repeat: "$weapon")[(set:$clicks to it + 1)]</tw-link>

It doesn't work because 'link-repeat' only operates properly with a string inside the inverted commas, not a variable. I suspect there are other reasons why it doesn't work as well.

I expect you have to add a second command after 'onclick=' but I'm not sure what.

1 Answer

0 votes
by (159k points)

Please use the Insert Code Snippet option when posting examples - it's the first button on the editor bar.

I believe the main issue is that you have two HTML elements, one a direct child of the other, both trying to handle the same click event.
eg. The HTML representing the (link-repeat:) macro and the parent tw-link element.

As you didn't supply the code for your clickCyclingLink Javascript function I can only assumed based on the code you did supply that you a using a hack to update the contents of the $weapon story variable. Is there a reason you're not passing the $clicks variable to the clickCyclingLink function so that you can uses the same hack to update its value as well?

by (250 points)

Apologies for not using the code snippet tool.

I'm using the Twine 2 cycling link macro from this website. I don't know how to update this so that it handles the $clicks variable as well.

...