How do I put apostrophes within strings inside of arrays?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GoGirlGaming

I’m making a game currently where I want there to be apostrophes within the dialogue. All of the dialogue is inside of a list, and for some reason simply printing the dialogue with the apostrophe works as shown in this example:

print("example: the girl\'s house")

But for some reason when I put that string in the list, I’m given an error saying “Parse Error: Invalid escape sequence”

dialogue = ["example: the girl\'s house"]

I don’t understand why this is happening, and I’d really like to have apostrophes in my dialogue, so if you know why this happening or how to fix this, I’d really appreciate the help.

:bust_in_silhouette: Reply From: MysteryGM
func _ready():
var dialogue = ["example: the girl\'s house"]

Works perfectly. A note the “girl's” part can also be just “girl’s” with no difference.
The \ symbol is only needed with " in my tests, as in:

var dialogue = ["\"example: the girl's house\""]

will print : “example: the girl’s house” with the " apostrophes.

It is unclear what that error is but maybe you should convert to string just in case.

print( str(dialogue[0])) #see if this works for you

Oh my gosh thank you so much for this answer. I realized because of your answer that the reason I couldn’t escape was because I was using an apostrophe and not quotes, and so instead of wasting my time on that, I was able to figure out that the root of the cause was that the font I was using didn’t have an apostrophe, so now I’m using a different font and it’s working. Thank you again for your answer.

GoGirlGaming | 2018-10-02 03:49

Thank you for clearing up what the problem was, as a person who uses a lot of custom fonts now I know what that error means; I was bound to run into the same problem sooner or later.

MysteryGM | 2018-10-02 11:45