Multicolored link which sets a variable and advances to next passage

If you are requesting technical assistance with Twine, please specify:
Twine Version: 2.3.9
Story Format: Sugarcube 2.31.1

So I found a thread on here about how to make multi color links. That part works fine, but I’m trying to get the link to set a variable as well as advancing to the next passage. As I have it now, “Confidence Point” is in a specific color (here class=“confidence”) and I want clicking on the link to subtract one of the player’s confidence points.

<<if $you.confidence gte 1>>OR you could <<nobr>><a data-passage="monday 2-counseling2a" class="link-internal" tabindex="0"> SPEND a <span class="confidence">Confidence Point</span> to choose any of these options.</a><</nobr>><<set $you.confidence-=1>><<else>><</if>>

Problem is the Confidence Point is being automatically subtracted when the passage containing this link loads, not when the player clicks on the link. Any ideas?

Your help, as always, is greatly appreciated!

I haven’t seen the original thread so am I not sure if you have tried with the <<link>> macro yet. If you can use it, try this:

<<if $you.confidence gte 1>>OR you could <span class="confidence"><<link "SPEND">><<set $you.confidence -= 1>><</link>></span> a Confidence Point to choose any of these options.<<else>><</if>>

Then in your stylesheet, put

.confidence a {color: purple}

or whatever color you need

Make sure to remove whatever style you had before.

yeah i tried the <<link>> macro and it didn’t work because I’m trying to get the <span class="confidence"> part within the link itself. Ideally, the link starts with the word “SPEND” and ends at the end of the sentence. The words “Confidence Point” would be the different class/color

I think I’m just gonna do it with plain text and a button. It wasn’t really a big deal, just something I thought would be cool

In that case you can put, wrapped in the <<if>> statements you had earlier:

<<link "SPEND a <span class='confidence'>Confidence Point</span> to choose any of these options.">><<set $you.confidence -= 1>><</link>>

The key is putting the class value in single quotes.

And in your stylesheet:

.confidence {color: purple}

1 Like

Single quotes! Of course! Thanks friend for the help!

In addition to Parjeter’s method, you might want to check out the “Multicolor Links” section of my Twine/SugarCube sample code collection for an alternate way to create those links.

If your question is resolved, then it’s also nice to mark the post that answered your question as the solution. Thanks! :slight_smile:

2 Likes

worked like a charm thanks y’all!