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 (159k 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.6k 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.
...