Godot Version
4.2.2
Question
i’m trying to learn how to use and handle json file as datafile and i’m struggling to find out how to properly set up my GameData script to load differents json file and for example use statsitemdata to fill the central main itemdata that are parsed in dictionary i’ve tried some things but it seems to not be working properly if you have any informations , advices or anythings to say feel free i’m open to everything i’m new on godot 4.2 and trying to learn
here is my gamedata script if needed : `extends Node
var content : Dictionary
var item_Data = {}
var loot_Data = {}
var ItemequipmentSlots_Data = {}
var item_data_file_path = “res://Singletons/itemData.json”
var itemEquipmentSlots_data_file_path = “res://Singletons/itemEquipmentSlots.json”
var monster_data_file_path = “res://Singletons/MonsterTable.json”
var Monster_Data = {}
var gold = 100000
func get_texture_name (ID = “0”):
return content[ID][“Texture”]
func get_Item_Name (ID = “0”):
return content[ID][“Name”]
func get_Item_equipableSlot (ID=“0”):
return content[ID][“equipableSlot”]
func get_Monster_Name (ID = “0”):
return content[ID][“Name”]
func _ready():
item_Data = load_json_file(item_data_file_path)
print(“item_Data has been loaded”)
print("item_Data: ", item_Data)
itemEquipmentSlots_data_file_path = load_json_file(itemEquipmentSlots_data_file_path)
print(“itemEquipmentSlots_data has been loaded”)
print("itemEquipmentSlots_data: ", ItemequipmentSlots_Data)
Monster_Data = load_json_file(monster_data_file_path)
print("monster data has been loaded Monster_Data: ", Monster_Data)
func load_json_file(filePath : String):
if FileAccess.file_exists(filePath):
print(“FileAcess to filepath correct”)
var dataFile = FileAccess.open(filePath, FileAccess.READ)
var parsedResult = JSON.parse_string(dataFile.get_as_text())
print(“Json.parse datafile : dataFile”)
if parsedResult is Dictionary:
print("Parsedresulted in Dictionary")
return parsedResult
else:
dataFile.close()
print("error reading files datafile closed")
if item_Data["equipableSlot"] == "to_be_filled_by_GameDataScript":
print("Equipableslot to be filled by gamedatascript")
item_Data["equipableSlot"] = ItemequipmentSlots_Data[item_Data["id"]]
print(item_Data)