File's store_line() stores all lines as one block of text.

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

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)
	file.close()

Results end up like: line 1line 2line 3

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…

Xrayez | 2018-07-11 18:25

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

avencherus | 2018-07-11 20:45

:bust_in_silhouette: Reply From: avencherus

Appending an “\r” is the solution.

I have no idea

cekew22975 | 2020-12-17 00:52

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.

Calinou | 2020-12-17 00:54