Adding quotation marks in String variables

Good day, you already read the title so let me give some context.

In the game I am working on, the characters have codenames and the stat chart often follows the template of: {name} "{codename}"

I tried to create a way so that if the player doesn’t know their codename (because they have yet to be told about codenames), it wouldn’t appear. So I this:

*comment: This is when the player still does not know a character's (in this case Klaus) codename
*create klaus 
*create codename " "

*stat_chart 
 percent klaus Klaus ${codename}  

*comment: When the player learns Klaus's codename 

"My codename is Comedian. Keep note of that." 

*set codename ""Comedian"" 

*comment: the reason why there are two quotation marks is so that when it 
appears the stat chart says: 

Klaus "Comedian"

This was how it is supposed to work. Whenever I try to do this, choicescript says it’s not valid. Although yes, I could create a variable like “know_codename” and place the stat chart underneath an *if statement, I am currently looking for a more efficient method.

Is there any way to put quotation mark in String variables?

1 Like

Would single quotation marks work? So the stat chart would say Klaus ‘Comedian’.

Or you might have to come up with a non-quotation-marks solution: Klaus, aka Comedian, for example.

2 Likes

Put an escape character inside the quote (in this case, backslash).

*set word "Bob says, \"that's what I said,\" he says loudly."
5 Likes

I just tried it out and it worked! Thanks for your input!

Brilliant question, brilliant answer @Szaal I wanted to use this a couple of years ago but thought it wasn’t possible, always great to learn a whole new world of possibilities is possible in CS :slight_smile: So helpful!

1 Like

Basically, escape character allows the printing of any characters without them being interpreted by the code, kinda like mini *comment but only for a single character. Javascript uses backslash, which is what CS based on.

While probably unnecessary, you can do this

*set word "The \$\{variable\} syntax prints the content of variable."
${word}
3 Likes

Yeah I heard of those before when I studied Java. I didn’t know they could be used in choicescript though.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.