I really wonder what this TextFile
for if it has no property Oo
I would have assumed you could use this import for .txt
files in your project, but it's still completely useless. Nothing is exposed: https://github.com/godotengine/godot/blob/master/scene/resources/text_file.cpp
So I think this resource was created just to allow the Godot Editor to open files as plain text in the script editor, so it's maybe not intended for use in a game: https://github.com/godotengine/godot/pull/21022
Anyways, you can load a file as text using a function like this:
func load_text_file(path):
var f = File.new()
var err = f.open(path, File.READ)
if err != OK:
printerr("Could not open file, error code ", err)
return ""
var text = f.get_as_text()
f.close()
return text
func save_text_file(text, path):
var f = File.new()
var err = f.open(path, File.WRITE)
if err != OK:
printerr("Could not write file, error code ", err)
return
f.store_string(text)
f.close()
Load from game resources:
var text = load_text_file("res://path/to/file.txt")
Load from player savegame:
var text = load_text_file("user://path/to/file.txt")
Check this out for more info about reading and writing to files: https://godotengine.org/qa/6491/read-%26-write