How do I reconstruct my inventory dictionary when using the save Godot function?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kaetaro1
 My inventory looks like this

{
“Inv1”: {
“Item”: 28012014
},
“Inv2”: {
“Item”: 48082016
},
“Inv3”: {
“Item”: 18012014
},
“Inv4”: {
“Item”: 28012014
},
“Inv5”: {
“Item”: 28012014
},
“Inv6”: {
“Item”: 18082016
},
“Inv7”: {
“Item”: 18012014
},
“Inv8”: {
“Item”: 48082016
},
“Inv9”: {
“Item”: 18012014
},
“Inv10”: {
“Item”: 48082016
},
“Inv11”: {
“Item”: 18012014
},
“Inv12”: {
“Item”: null
},
“Inv13”: {
“Item”: null
},
“Inv14”: {
“Item”: null
},
“Inv15”: {
“Item”: null
},
“Inv16”: {
“Item”: null
},
“Inv17”: {
“Item”: null
},
“Inv18”: {
“Item”: null
},
“Inv19”: {
“Item”: null
},
“Inv20”: {
“Item”: null
},
“Inv21”: {
“Item”: null
},
“Inv22”: {
“Item”: null
},
“Inv23”: {
“Item”: null
},
“Inv24”: {
“Item”: null
},
“Inv25”: {
“Item”: null
},
“Inv26”: {
“Item”: null
},
“Inv27”: {
“Item”: null
},
“Inv28”: {
“Item”: null
}

My save function looks like this

func on_SaveInventory():
var index = 0
print(“saving”)
var save_inventory_file = File.new()
save_inventory_file.open(“user://inv_data_file.json”, File.WRITE)
save_inventory_file.store_line(to_json(inv_data))
save_inventory_file.close()

My read function looks like this

:bust_in_silhouette: Reply From: rossunger

you might want to use the str2var and var2str functions instead of json :slight_smile: