I have made a save system, and it works perfectly in one scene. I have some variables I'd like to save - two to check if the player has gained a spell/whether an icon should show in the menu, one for the player's position and one to check which scene the player saved in. Unfortunately, when I save in a different scene and load the game it crashes, scene_path and the player's position are stored as nil (for some reason the first two can save and load fine) and I get the "cannot convert argument 1 from nil to string" error. I also get two other messages:
decode_variant: Condition "len < 4" is true. Returned: ERR_INVALID_DATA
get_var: Error when trying to encode Variant.
My code:
func _process(_delta):
if Input.is_action_just_pressed("ui_c"):
scene_path = get_tree().current_scene.filename
file.open("res://data.res", file.WRITE)
file.store_var(data_to_save["firespellimagevisible"])
file.store_var(data_to_save["waterspellimagevisible"])
file.store_var(scene_path)
file.store_var(get_node("/root/Node2D/KinematicBody2D").position)
file.close()
check_for_spell()
func _ready():
if file.file_exists("res://data.res"):
file.open("res://data.res", File.READ)
data_to_save["firespellimagevisible"] = file.get_var()
data_to_save["waterspellimagevisible"] = file.get_var()
scene_path = file.get_var()
load(scene_path)
get_node("/root/Node2D/KinematicBody2D").position = file.get_var()
file.close()
I've got no idea what len is or what is causing these errors. Any help is appreciated.