0 votes
by (140 points)

I'm trying to use the tooltip tool using the title attribute, however I intend to use a variable in the tooltip but it is not working properly

I'm doing:

<a @title="$ds">$nm</a>

 

3 Answers

0 votes
by (2.4k points)

What story format are you using? Sugarcube, Harlowe,...?

In Sugarcube, when I need to use a Sugarcube variable in a HTML element, I use the <<print>> macro to print what would be the HTML code with the variables:

<<print '<a title="' + $tooltip + '">' + $text + "</a>">>

If you are using other format, I'm not sure if its print function will allow this.

(I think it's called the "Stupid Print Trick" xD)

0 votes
by (159k points)

> but it is not working properly.

I created a new SugarCube 2.x project and placed the following within the first Passage.

<<set $ds to "This is the tooltip">>
<<set $nm to "This is the link text">>

<a @title="$ds">$nm</a>

When I viewed the story HTML file the first page contained a HTML anchor element with the correct link text, and it displayed the correct tooltip when I hovered my mouse cursor over the link text.

 What exactly do you mean when you say it isn't "working properly"?

by (140 points)
The tooltip is showing "$nm" instead of "This is the tooltip"
by (44.7k points)
What version of SugarCube are you using?  AttributeDirectives were added in v2.21.0, so if you have an older version then they won't work at all.  Also, as I mentioned below, there was a bugfix for them in v2.23.5.
0 votes
by (44.7k points)

There was a bugfix for attribute directives in SugarCube v2.23.5.  I don't know if that's the cause of your problems, but if you have an older version of SugarCube (as of now the current version is v2.28.2) then you might want to download the latest version and install it to see if that fixes the problem.

Hope that helps!  :-)

...