Hy community,
is there a simple solution to export the final score to a .txt file ?
thanks a lot !!
Hy community,
is there a simple solution to export the final score to a .txt file ?
thanks a lot !!
The file class is probably what you are looking for: https://docs.godotengine.org/en/3.1/classes/class_file.html
Haven't used this myself though.
This is also worth reading through: http://docs.godotengine.org/en/latest/tutorials/io/saving_games.html
func save_score(save_path, score): # The path must end with .txt to create a txt-file
var f = File.new()
f.open(save_path, File.WRITE)
f.store_line(to_json(score))
f.close()
func read_score(save_path) -> float:
var score: float
var f = File.new()
f.open(save_path, File.READ)
score = parse_json(f.get_line)
return score
If you need to save data that doesn't need to be read in other programs (for interoperability reasons), consider using the ConfigFile class instead of JSON. Unlike JSON, ConfigFile is strongly typed and can serialize any Godot datatype out of the box.