Error trying to open a file. What am I doing wrong?

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

I am trying to implement save/load data from a file following a tutorial ( but it fails. When I print the error, it just says 7. How can I know what error 7 means? This is the code:

onready var path = "user://save.dat"

func load_data():
var file =
var err =, File.READ)
if err != OK:
	print("error opening data file")
	return default_level_info		
var read = {}
read = file.get_var()
return read 
:bust_in_silhouette: Reply From: Calinou

To know what the error code means, check the Error enum documentation. 7 is for ERR_FILE_NOT_FOUND. To read a file, it needs to exist already. To create the file if it doesn’t exist (and truncate it if it exists), use the File.WRITE mode instead of File.READ.

Call file_exists(path) from your File instance to check whether a file exists at the given path.

Thank you so much, it worked exactly as you described.

korayozbay | 2020-05-05 13:19