Howdy, Stranger!

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

Able to use a variable as a span ID?

Sorry, pretty new to this, but my combined google-fu and experimentation has been failing me for about an hour now.

In sugarcube, is it possible to use a variable as a span ID, or to otherwise provide a dynamic way to generate span IDs on the fly? (I also tried workarounds with using both Print and Replace, but that failed for reasons I can't quite understand.)

For reference, I was trying to work on this: <<widget nestdialogue>><span id= "bob"><<click $args[0]>><<replace "#bob">><i>$args[0]</i><br>$args[1]<br>$args[2]<</replace>></span><</click>><</widget>>

and while it works, I'd like to have the text remain after each iteration. So, for me, a workaround is just as good as an answer to the title question. Thanks.

Comments

  • Maybe instead of replace try append?
  • edited February 2017
    <<linkappend>> essentially does what you're asking, so maybe start there. I'm not sure which version of sugarcube you're using, but you can always upgrade to the latest if you need to.

    I think you need to use jQuery, or at least JavaScript to add an id with a variable. You can add classes though.
  • First. You should always state the story format you're using and its version, because advice will tend to vary based on that information.

    In sugarcube, is it possible to use a variable as a span ID, or to otherwise provide a dynamic way to generate span IDs on the fly? (I also tried workarounds with using both Print and Replace, but that failed for reasons I can't quite understand.)
    Yes, however, you'd have to use the Stupid Print Trick™. For example:
    <<print '<span id="' + $aStoryVariable + '">…</span>'>>
    


    You could also dip into JavaScript, but that's a new level of complexity.

    For reference, I was trying to work on this: <<widget nestdialogue>><span id= "bob"><<click $args[0]>><<replace "#bob">><i>$args[0]</i><br>$args[1]<br>$args[2]<</replace>></span><</click>><</widget>>

    and while it works, I'd like to have the text remain after each iteration. So, for me, a workaround is just as good as an answer to the title question. Thanks.
    Please use the code tag when posting code or markup—it's C on the editor bar.

    You have the opening <span> tag outside of the <<click>> and its closing tag inside the <<click>>, which is never going to work. You cannot interleave the tags of non-void/container pieces of markup like that.

    I'm pretty sure I understand what you're going for in a broad sense, however, I'm unclear on how you were intending to use that widget to achieve it. Can you give an example of how you envisioned that being used?
  • edited February 2017
    Ok, sorry for delay, got new comp in mail recently and have been shifting everything over.
    Version is 1.0.3.4 of Sugarcube, in Twine 2.0.11.

    Widget functionality is: args[0] is dialogue the player says. args[1] is response text, and args[2] is a recursive call to another nestdialogue or dialogue piece.

    Got it to work using "stupid print trick."
    <<widget nestdialogue>><<print '<span id="' + $aRandom + '">'+'<<click $args[0]>>'+'<<replace "#' + $aRandom + '">>'+'<i>$args[0]</i><br>$args[1]<br>$args[2]'+'<</replace>>'+'<</click>>'+'</span>'>><<set $aRandom += "q">><</widget>>
    

    Thank you all for the help.
Sign In or Register to comment.