0 votes
by (130 points)
I've just switched from harlowe to sugarcube 2.21.0, and I have a custom character name set by the variable $name. Using that variable in links for Harlowe looked like this:

[[My name is $name. It's a pleasure to meet you.|passage1|]]

But in sugarcube, instead of printing the variable, it just displays "$name" where I want the variable to be.

I've found a way to print variables in sugarcube links which looks like this:

<<link `"My name is " + $name` "passage1">><</link>>

Which will print the variable correctly, but only if its the last word in the link.

My question is, how can I print a variable in the middle of the link's displayed text rather than only at the end?

1 Answer

+1 vote
by (157k points)

Please use the Insert Code Snippet button when adding code examples to your questions and comments.

You almost worked out the answer yourself, you simply need to use another 'plus sign' to add the trailing String literal you want.

<<link `"My name is " + $name + ", what is yours?"` "passage1">><</link>>


by (68.4k points)

You may do the same thing with the link markup.  For example:

 [["My name is " + $name + ". It's a pleasure to meet you."|passage1]]


by (130 points)
Thanks! I knew there had to be something I was missing, this worked perfectly.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.