Why are my escape characters printing \n?

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

I’m making a dialogue system and am struggling with escape characters, specifically ‘\n’.

Because a single text entry in the CastleDB database I’m using doesn’t support new paragraphs, I’m using escape characters but ‘\n’ within the string prints to ‘\n’, not a space, in the dialog box.

I’ve tried using the format string function with ‘some text here {space} some more text’, with the space referencing a string consisting of just \n which is added in Godot. This still prints \n. If I feed some constant test string with \n in the middle directly into the function which displays the dialog text, it adds a space correctly so I’m not really sure what is going on here.

I don’t have a computer science background (I’ve done some C up until pointers, at which point I decided to return later).

Is there something going on in the background with my string in gdscript? It prints out just like you would expect a string to, apart from ignoring my escape characters.

Could it be something to do with the fact that it comes in as if from JSON? As far as I’m aware, even if a string is chopped up and reassembled, it should still just behave like a string…?!

Edit: I wasn’t really sure what code to include before, but I thought I’d try re-inputting the values. I only got part way to implementing that when I had this unexpected result from my function:

func re_input(FormatDict):
for i in FormatDict:
	if FormatDict[i]["value"] == "\n":
		print("true")
	else:
		print(eventFormatStringDict[i]["value"])

Which would output:

\n
\n

Further edit:

I have now solved the problem. I was able to look inside the CastleDB data through GitHub and for some reason the \n was stored as \n. Now I know what the problem is I can fix it!

Thanks,

James