Disable auto new line

Godot Version

v4.3.stable.official [77dcf97d8]

Question

I am making dialogue that loads text from txt file. But when saving text godot automatically adds new line which adds /n to the end. Is there is way to disable this?

Well I just tried this and did not add a /n. Also the docs says it will not

func save_to_file(content):
	var file = FileAccess.open("res://save_game.txt", FileAccess.WRITE)
	file.store_string(content)

func _ready():
	
	var s="This is a test"
	save_to_file(s)
	return

How are you saving the text? Can you show us the code?

That looks like the output, not the code you wrote to save the information.

When editing raw text file saving adds new empty line.

Oh… yeah that is actually a feature of the editor because for some reason gdscript files need that newline. AFAIK, there is no way to turn that off. However, you can right-click on the file and select Open In External Program. I open text files, md files, etc in Visual Studio Code and edit them there.

You might find one of these plugins helpful. They’re both in active development. The first also comes with a list of tutorial videos:

If you really want to do it yourself, I recommend you look into using Resources to do that.

1 Like

It’s a standard approach to ensure all files have a newline at end of file (to avoid issues when using cat on them among other things). Requiring files to not have a newline at end of file is therefore considered bad practice.

If you want to get rid of the newline when reading the file, use String.trim_suffix("\n") when reading the file.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.