Simple Javascript string question (hopefully)

0 favourites
  • 5 posts
From the Asset Store
This collection of music is the beautiful performance of rather small strings ensemble (8 first violins, 6 second violin
  • The simple question: what is wrong with the line of script shown? I'm using the same string value passed into the "load from json string" line above, so I don't understand why it's not compiling for the script.

    Where I'm going with this? I want to convert my arrays to base64 strings for security/privacy and save the base64 string to a variable in the code. Then at runtime, I want to use javascript to convert them back to standard strings and load the string into the array. The shown code doesn't have the base64 encoding yet.

    Thanks

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Why are you setting the value in the script? Just put that string into the variable as its default value. You won't need double quotation marks.

  • That's a much cleaner and simpler way to do it. Plus I dont have to go into notepad++, remove EOLs/returns, escape the quotes, etc. Thanks!

    My workflow now is encode the string to b64 using an external tool and paste that val when setting the arrayString variable in the code. Then I decode at runtime using the atob script you shared. Works great!

  • The problem in your original post is using double quotes in strings is syntax specific to Construct expressions, and it is invalid in JavaScript. In JS you need to use \" for a quote inside a string, or use a single-quote string so double-quotes are allowed unescaped, or use a template string with `.

  • That makes sense, thanks Ashley for the clarification.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)