Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Variable links

This is really straight forward: Is there any way to use a variable as a link? Say, if the variable equals a passage name, is there any way to get Twine to recognize that? Or do you just have to go with a wall of "if" statements if you want to have a variable link like that?

Comments

  • edited May 2015
    First: Always specify which story format you are using. There are multiple and they have differences.


    Yes. The wiki link markup can accept a $variable as its link component straight up. How you use a $variable for the optional text component differs between the vanilla formats and SugarCube.

    Vanilla story formats [Jonah, Sugarcane, Responsive] (see: link):
    → With just the passage title given as a $variable
    [[$passage]]
    
    → With both the link text and passage title given as $variables
    [[<<print $text>>|$passage]]
    

    SugarCube (see: Links):
    → With just the passage title given as a $variable
    [[$passage]]
    
    → With both the link text and passage title given as $variables
    [[$text|$passage]]
    

    Alternatively, you could also <<print>> the entire link, like so:
    → With just the passage title given as a $variable
    <<print "[[" + $passage + "]]">>
    
    → With both the link text and passage title given as $variables
    <<print "[[" + $text + "|" + $passage + "]]">>
    

  • Alternatively, you could also <<print>> the entire link, like so:
    → With just the passage title given as a $variable
    <<print "[[" + $passage + "]]">>
    
    → With both the link text and passage title given as $variables
    <<print "[[" + $text + "|" + $passage + "]]">>
    

    I have to say, I've found that last trick to be *very* useful when printing links within loops when the link depends on the loop variable (a distinct link to act on a particular item in an inventory list, for instance). Regular links won't resolve until the user clicks them, which is long after the loop is already finished and the loop variable is either at its final value or reset. Constructed links will resolve when they're constructed and the variable is at the correct place in the loop.
Sign In or Register to comment.