0 votes
by (2.4k points)

Hello there!

I was wondering, is there any way to use <<link>> with an image? Right now I'm doing 

 

[img[$Helmet[1]][Change your equipment][$helmet to $Helmet[1]]]

This, so it displays the image of the helmet you can wear, and when you click on the image, it gets equiped. 

But I'd like to modify more than one variable when the player equips the helmet. How could I do it ? 

<<link>> works awesomely, but I don't know if I can use it with images. If I can, how ?

Thanks a lot !

1 Answer

0 votes
by (68.6k points)
selected by
 
Best answer

Yes.  As noted in its documentation, simply pass the image markup as an argument to the macro.

<<link [img[$Helmet[1] ][Change your equipment]]>>
/* code here */
<</link>>

EDIT: Due to a bug, you need an extra space after the variable's square brackets.  I've modified the example above.

by (2.4k points)
reshown by
Does that work with the 2.21 version of Twine and sugarcube? It says since 2.8, and I'm getting an error when I try to use this :(
by (68.6k points)

First.  Please don't ask a new question which is simply a clarification to an answer of a previous question, that's what comments are for.

Apparently there's currently a bug when using the image markup syntax as an argument to macro calls when using a variable and square bracket notation.  You can workaround this by putting a space between the variable's square bracket access and the markup's square bracket.  For example:

<<link [img[$Helmet[1] ][Change your equipment]]>>
	<<set $helmet to $Helmet[1]>>
<</link>>

In general, you don't want to stuff extra whitespace where you don't need it, but in this case the extra space won't affect anything adversely and it works around the parsing bug.

by (44.7k points)

No, the parser will choke on the brackets for the array.

You'll have to use TheMadExile's trick above or copy the array value to a temporary variable before doing that.  For example:

<<set _helm = $Helmet[1]>>
<<link [img[_helm][Change your equipment]]>>
/* code here */
<</link>>

Hope that helps!

EDIT: Heh... TheMadExile answered about 30 seconds before I did.

by (2.4k points)
There have been many times in which my comment asking a new question was never seen, which is why I'd rather ask a new question now, instead of posting a comment.

It works perfectly, thanks a lot to you both!
by (68.6k points)
There's a difference between never seen and never replied to, you only know the latter has happened.  People have lives outside of answering questions here and sometimes things fall through the cracks.  It's also possible that the person in question simply didn't think your comment needed a reply.  If a particular comment hasn't gotten a reply after a few days, and you really think it should, just bump the question with a new comment.

Again.  I'm only speaking of clarifications to an existing question.  New queries should, of course, be asked as new questions.
...