Adding more text to <<link>>

Twine Version: 2.3.15
Story Format: SugarCube 2.34.1

Hello, I’m trying to add more text to a <<link>> macro - the second piece of text being a different colour, but that has been omitted from my code for simplicity. My code is as follows:

<<link "Work" + " More text goes here">>
	<<set $ += 10>>
	<<goto cafeWork>>

Using the above text the link shows up only as “Work” red, any ideas how to remedy this?

Welcome Serena,

With a <<link>><</link>> macro, barring use of picture as the clickable onscreen object, you need a string of characters to be the text that will be read by the player, and as an option a second string of characters as the passage the story will be moved to.
The ‘+’ in your example won’t work, because it’s the way to add two strings of character in a <<set>> macro.
However you can use;text@@ to give a specific style to a string of characters, so you can use it inside the first string of your link.

Given .red already defined

<<link ";Work@@ More text goes here" "wherever the story should proceed">><</link>>

You should see ‘Work’ in red, while ’ More text goes there’ will be in blue.

1 Like

The Macro Arguments section of the documentation explains why your concatenation of two String literals didn’t work when performed while passing an argument to a macro call. You need to wrap your concatenation within back-quote characters so that the concatenation is performed before the result is passed to the macro as an argument.

There is also a potential issue with the (unnecessary) <<goto>> macro call, as the Passage Name you are passing to it should be either a String value (eg. "cafeWork") or a Markup based Link.

The following two examples are corrected variations of your own, the 1st uses the passageName argument of the <<link>> macro, and the 2nd continues to use a <<goto>> macro.

<<link `"Work" + " More text goes here"` "cafeWork">>
	<<set $ += 10>>


<<link `"Work" + " More text goes here"`>>
	<<set $ += 10>>
	<<goto "cafeWork">>

Adding onto what @souppilouliouma said, instead of using Sugarcube’s markup, you can actually use html markup within a link (to a limited extent).

So if you start on a plain page with

<span style='color: red'>Work</span> and more text

You can just paste it into your link like this:

<<link "<span style='color: red'>Work</span> and more text">>
	<<set $ += 10>>
	<<goto cafeWork>>

Be sure to use single, not double, quotes around color: red


Thank you all very much! Everything said in this thread has been very helpful! I very much appreciate it.