Entering a multi-line string in JS

Hello,

I’ve got this code that works…

txt = ""
txt += "Level 1

"
txt += “In a hole in the ground”
txt += “there lived a ninja Hobbit”

But to save re-typeing stuff when dropping in text from a word processor I’d like to be able to do something like this…

txt ="
Level 1
  
In a hole in the ground
there lived a ninja Hobbit.
";

Stuff on the web related to normal javascript suggests this should work:

txt ="\
Level 1\
\
In a hole in the ground\
there lived a ninja Hobbit.\
";

But it doesn’t.

Any ideas/suggestions?

Thanks…

@reincarnationfish, UnityScript(what people call JavaScript) isn’t JavaScript, it shares some syntax from JavaScript, but it’s not.

Honestly the wisest choice in this case would be to load the text from files(text or whatever), whether that is text or otherwise and retain the format that way. If you’re creating a per level story or stories(topics, etc), the system would be better served to have a parser/loader which would ensure you’re not adding more to the code base then needed.

What format, that depends on your desired output and the amount of data, but you won’t have to deal with the carriage returns /r/n or whatever system you’re on.

If that isn’t something that makes sense, then what @DandedIn stated would work.

Maybe you should try

But not only slash ( \ )?