Howdy, Stranger!

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

How to print a string that has a dollar sign

Suppose I have a variable $someVar that contains the following text: $eric

If I put $someVar in my passage I get 0, because it's trying to evaluate $eric as a variable. (print: $someVar) does the same thing. How can I print that variable as a string literal without it being evaluated?


  • Wrap the dollar sign $ in backtick (or grave accent) ` characters, it is the character under the tilde ~ character to the left of the one 1 key.
    (set: $someVar to "`$`eric")
    someVar: $someVar
  • Thanks for the answer, that works and can solve my problem.

    It's a hassle for strings generated by Javascript, because they have to escape them manually. Also, backslash is the escape character in strings being passed to Javascript. Where does that string parsing happen? In Harlowe, or in shared Twine code? I'd like to explore other ways to mark strings as literals (without breaking existing syntax of course) and maybe submit a patch.
  • The Twine application itself does very little to the contents of passages when it publishes (generates) a story HTML file, you can see exactly what happens by looking at the following three publish methods:
    a. storyformat.publish
    b. story.publish
    c. passage.publish

    All the real work is done by the javascript engine contained in each of the story formats, and as each engine is unique you would need to look at it's source code to see what passage text processing it does.
Sign In or Register to comment.