+1 vote

If I write this string in the script editor: "1234\n1234", the line will break, but if I write the same thing in a file, load it and print its contents, no line break occurs and the string is shown as is.
In the editor:
enter image description here

In a file:
enter image description here
How to make it break the line both in the editor and in a file?

in Engine by (195 points)

1 Answer

+1 vote
Best answer

In a file, you write the actual line break, by pressing the Enter key. You should also ensure your editor writes the correct character (Windows style is \r\n, Mac style is \r and Unix \n, but it's a matter of configuring your editor).

If you really need to write an explicit line break with "\n" for some reason, I guess you could do a string replace in GDScript to change "\\n" (note the escape character being escaped itself) into "\n".

by (27,774 points)
selected by

Many thanks! I'm making a dialogue system and store the dialogues in a file with special formatting and manually breaking the lines makes the text harder to navigate in. The second option is perfect in my case!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.