It looks like you're new here. If you want to get involved, click one of these buttons!
[[Link Text|$variable]] [[Link Text|<<$variable>>]] [[Link Text|<<print $variable]]The all didn't work and created new passages which is not what I do not want it to do.
And I thought, maybe it might work. Then it did. The below code now makes the link in the passage act dynamically.<<set $actor to "Ginger">> <<if $location[$actor] is passage()>> <<print "[[Talk to " + $actor + "|Talk_" + $actor + "][$chat to '" + $actor + "']]">> <<endif>>
<<print "[[Link Text|" + $variable + "]]">>It still made a passage but when I played the passage with the dynamic link, it took me where I want to go. I deleted the created passage and it still works. I just don't know how to remove the flow chart line, but I guess that's ok for now.
Comments
Should work, without needing to do the print trick. It will create a passage that you'll need to delete on Twine 2.x, however.
When you tried this, did it just not work at all?
I just tried this just now, created a new story for it and checked the story format. It now works as you suggested.
Edit: The current story format of the first post is sugarcube 2.12.
(I thought twine changed it to 2.16...)
I couldn't say what your issue was. At a guess, however, you probably weren't defining your variable properly, misspelled it, or didn't delete the passage automatically created by Twine 2. I'll further guess that the latter is probably the culprit.
To explain why the latter could cause issues. As noted within the documentation, the link component may either be plain text or any valid TwineScript expression. SugarCube checks them in that order as well, meaning it checks to see if a passage by the name exists before it attempts to evaluate the link as code. Thus, if you have a passage named $variable, SugarCube assumes that the link is supposed to go to that passage. Basically, it prioritizes treating the link component as a passage over as code.
The reason why the Stupid Print Trick™ worked in this case, is because it forced the variable to be evaluated as part of the <<print>> rather than as part of link markup itself. In other words, the following code: Produces the following link: (assume $variable has the value "Over There")
I guess I'm stuck using the Stupid trick at least for now.
Beyond that, rather than using the Stupid Print Trick™, just use the separate argument version of the <<link>> macro. For example:
And thank you for the suggestion! I haven't thought of that. It sounds that the is bad practice? Why is it?