invalid get index 'var' (on base: 'float')

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

Help This is the code that i use to store skins and i don’t know why it won’t load.

Image of the error

:bust_in_silhouette: Reply From: exuin

When you store your save data, you’re not storing it as json but you are trying to parse the saved data as json when you load it. Use the to_json() function on a dictionary in order to properly store the data.

Tried but now when i close the program both of the variables reset to 0 0 but the savefile remains 1 0

Video

andrymas | 2021-01-07 18:52

Maybe it’s because you’re converting it to an int when the program has it as a float in the previous error message?

exuin | 2021-01-08 01:45

Still haven’t figured out the error but i’ve deleted that code and tried this one that works: https://kidscancode.org/godot_recipes/basics/file_io/

extends Node

var skin1own = 0
var skinequip = 0


var score_file = "user://skin.save"

func save_skin():
    var file = File.new()
    file.open(score_file, File.WRITE)
    file.store_var(skinequip)
	    file.store_var(skin1own)
    file.close()


func load_skin():
    var file = File.new()
    if file.file_exists(score_file):
	    file.open(score_file, File.READ)
	    skinequip = file.get_var()
	    skin1own = file.get_var()
	    file.close()
    else:
	    skinequip = 0
	    skin1own = 0
	

andrymas | 2021-01-08 14:28