Invalid call. Nonexistent function 'store_line' in base 'Nil'

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

func save_game():
var save_game: File = get_file(true)
var data: Dictionary = {
“PlayerSelect”: Game.PlayerSelect,
“FirstLaunch”: Game.FirstLaunch,
}
save_game.store_line(to_json(data))
save_game.close()

func load_game():
var save_game: File = get_file(false)
if not save_game:
return
while not save_game.eof_reached():
var current_line = parse_json(save_game.get_line())
if current_line:
Game.PlayerSelect = current_line[“PlayerSelect”]
Game.FirstLaunch = current_line[“FirstLaunch”]
save_game.close()

:bust_in_silhouette: Reply From: zhyrin

The error message you got means you try to call a function store_line on a variable that has a value of null/Nil. This happens on line 7 in this snippet.
So your savegame is not a File object, it’s null.
Investigate why getfile() or get_file() might return a null.