Howdy, Stranger!

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

[Harlowe] Can't escape a single quote

edited April 2016 in Help! with 2.0
I have code similar to this:
(set: $a to (datamap: "A", ""))
(set: $b to "(set: $a's 'A' to it +       ' Don't! '      )")
(print: $b)
(print: $a's A)

The single quote in 'Don't' needs escaping, or Harlowe will think it's the closing quote of the string and all will break.

But surrounding that single quote with tildes doesn't work. The engine says: Unterminated template literal

Using double quotes is not an option since all that is already inside the double quotes that define $b.

Is there any solution to this? Right now, I have to write "do not" and "does not" all along my game, since practically all the content is defined in blocks like these (yes, my game is stupidly complex).

Comments

  • edited April 2016
    You need to escape the single quote within the "Don't!". To escape a quote, precede it with a backslash. For example:
    ' Don\'t! '
    
    In this particular instance, since you're nesting that quoted string within another string which gets evaluated, printed in this case, you will need to escape the backslash itself (i.e. use two backslashes). For example:
    (set: $b to "(set: $a's 'A' to it +       ' Don\\'t! '      )")
    
    That will evaluate to the following when `$b` is set:
    (set: $a's 'A' to it +       ' Don\'t! '      )
    
    Which evaluates to the following when `$a's 'A'` is finally set:
     Don't! 
    
  • Thank you SO much!

    Escaping the escape character. I had already tried the backslash, but I'd never think of doubling it. That's a good lesson. Thanks again.
Sign In or Register to comment.