I have a problem with "load and save" function

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

Okay, so I tried to go with a tutorial on load and save function and once I wrote the code, it showed that there is expected end of statement (var).

var error : int ResourceSaver.save(save_path, save_game)

I couldn’t make it work, unless I removed the " : " and " int "

Does it work if you add an = between the variable and the ResourceSaver?

var error : int = ResourceSaver.save(save_path, save_game)

i_love_godot | 2019-12-11 13:34

:bust_in_silhouette: Reply From: AiTechEye

If you just need to save a variable or a dictionary this works fine (using it in my projects)

Everything in the “save” dictionary will be saved to the file, call the load_data to load it.

var save = {}

func save_data():
	var file = File.new()
	file.open("user://save",file.WRITE_READ)
	file.store_var(save)
	file.close()
	
func load_data():
	var file = File.new()
	if not file.file_exists("user://save"):
		return false
	file.open("user://save",file.READ)
	save = file.get_var()
	file.close()

check if the vaiable exist

func _ready():
	if not save.has("item"):
		save.item = {"worlds":{},"count":0}

or just set true

save.level_finished = true