godot 4.2.1
I’m new to godot and was wondering about ways to make saves and load them. I have this code currently which is in my auto load scene. all the things I am trying to save a var’s in the scripts. when the function save is run it outputs this error “attempt to call function ’ store_var’ in base ‘null instance’ on a null instance”
func save():
var file = FileAccess.open(save_path, FileAccess.WRITE)
file.store_var(gold)
file.store_var(health)
file.store_var(highestFloor)
file.store_var(giveDaveGold)
file.store_var(daveInMainLevel)
file.store_var(daveShopOpen)
file.store_var(playerSpeed)
func load_data():
if FileAccess.file_exists(save_path):
var file = FileAccess.open(save_path, FileAccess.READ)
gold = file.get_var(gold)
health = file.get_var(health)
highestFloor = file.get_var(highestFloor)
giveDaveGold = file.get_var(giveDaveGold)
daveInMainLevel = file.get_var(daveInMainLevel)
daveShopOpen = file.get_var(daveShopOpen)
playerSpeed = file.get_var(playerSpeed)
else:
print_debug(“no save”)
func _on_button_pressed():
save()
func _ready():
load_data()