Howdy, Stranger!

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

Variable in Div value

edited October 2015 in Help! with 2.0
I'd like to use a Twine Harlowe variable in a HTML DIV value, but it doesn't work for me :(
<progress id="health" value=$strength max="35"></progress>
Any help would be appreciated.

Comments

  • edited October 2015
    Here is how I'd hope it would work -

    https://jsbin.com/worufedora/edit?html,js,output

    I know this works (without the variable) -
    (print: "<progress id='health' value=25 max=35></progress>")
    
    But when I add the variable (..."+$strength+"...) it says "the number 25 isn't the same type of data"

    However, if I do the following it works -
    (set: $strength = "25")
    (print: "<progress id='health' value="+$strength+" max=35></progress>")
    
    But then I can't do additions or subtraction with $strength.
    ... unless I do something like (set: strengthInt = parseInt($strength,10))

    Is there some formatting I'm missing?
  • You need to use the (text:) macro, which will output a stringified version of $strength. So, you want something like the following:
    (print: '<progress id="health" value="' + (text: $strength) + '" max="35"></progress>')
    
  • MadExile

    Thank you so much - This works perfectly!
Sign In or Register to comment.