Problem Invalid call. Nonexistent function 'clear' in base '_File'.

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

Why am getting this:
Invalid call. Nonexistent function ‘clear’ in base ‘_File’.
Here is My code:

func get_data():
var file = File.new()

if not file.file_exists(SAVEGAME):
	save_data = {"Player_name":"Unnamed"}
	save_game()
file.open(SAVEGAME,File.READ)
var content = file.get_as_text()
var data = parse_json(content)
save_data = data
file.clear()
return(data)

What is the Solution ?

:bust_in_silhouette: Reply From: jgodfrey

This looks like 3.x code (due the use of the File class). Regardless, the File class doesn’t have a clear() function, as the error states. See the docs here:

What are you trying to do with that clear() call? Maybe you meant to use close()?

yes i meant to use close

User5080 | 2023-06-11 18:20