+2 votes

Been puzzling over this for an hour, but using store_line(some_string) or even store_string(some_string) produces a file that has no line breaks. They appear in some programs, but in notepad they do not.

More importantly I'm trying to output scripts for command line, and these won't work as .bat files. The lines will all get executed as one line.

Any suggestions on how to coax the output file into having carriage returns?

A basic code example would look like this:

var output = []

output.append("line 1")
output.append("line 2")
output.append("line 3")

var file = File.new()

if(file.open("res://script.bat", File.WRITE) == OK):
    for line in output: file.store_line(line)

Results end up like: line 1line 2line 3

in Engine by (5,248 points)

Have you tried store_string()?
Alternatively, you could try write new line directly for each line:
file.store_line('\n') # append new line, not sure whether that would work...

store_line(line + "\r") seems to work.

1 Answer

+2 votes
Best answer

Appending an "\r" is the solution.

by (5,248 points)

I have no idea

For the record, this issue is caused by old versions of Windows Notepad not supporting LF line endings. Godot will write LF line endings when using File.store_line(), as this is the expected behavior on all non-Windows platforms.

Recent versions of Windows 10 now support LF line endings in Notepad, so this should no longer be an issue.

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 Frequently asked questions and 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 [email protected] with your username.