hello,
I am making a simple inventory and i have a problem
am making a global file that contains empty dictionary that receives data from other script
what i want is to save this dictionary to json file then when i play the game again it read from json back to global dictionary.
i think it is complicated but maybe someone have a different idea to share it with me.
here is the global file am talking about
extends Node
const FILE_NAME = "user://game-data.json"
var inventory = {} # here i want it to read from json file
func _ready():
var file = File.new()
if file.file_exists(FILE_NAME):
file.open(FILE_NAME, File.READ)
var data = {}
var text = file.get_as_text()
data = parse_json(text)
inventory = data
file.close()
func save_game():
var file = File.new()
file.open(FILE_NAME, File.WRITE)
file.store_line(to_json(inventory))
file.close()
it works when i save it to json and give me this result
{"0":["Potion",4]}
the json result explained ---> slotindex: [itemname, item_quantity]