## NPCs.gd extends Entity #const file_path = "res://Game/Data/Enemies.json" var enemy_data_dict: Dictionary = {} func _ready() -> void: pass func load_enemy_data(file_path: String) -> void: var file = FileAccess.open(file_path, FileAccess.READ) if file: var json_data = JSON.parse_string(file.get_as_text()) if json_data.error == OK: if typeof(json_data.result) == TYPE_DICTIONARY: enemy_data_dict = json_data.result print("Loaded Enemy Data Successfully") file.close() else: print("JSON Error: Parsed Data is not a Dictionary") else: print("Error parsing JSON: ", json_data.error_string) file.close() else: print("Failed to open File: ", file_path) func get_enemy_data(enemy_key: String) -> Dictionary: #if enemy_key in enemy_data_dict: return enemy_data_dict.get(enemy_key, {}) #return {} ## if json_data.error == OK: ## In the above code is where the error is. ## The Error is a StackTrace Error: "Invalid access to property or key 'error' on a base object of type 'Dictionary" ## The following code is where load_enemy_data() is called and is also throwing an error but I think the problem is in the above code. ## ## Enemy_Screen.gd extends Entity @onready var enemy_ui = preload("res://Scripts/Entities/EnemyScript.gd").new() @onready var npc_manager = preload("res://Scripts/Entities/NPCs.gd").new() func _ready() -> void: npc_manager.load_enemy_data("res://Game/Data/Enemies.json") ##THIS IS WHERE THE ERROR IS IN THIS FILE if typeof(npc_manager.enemy_data_dict) == TYPE_DICTIONARY and npc_manager.enemy_data_dict.size() > 0: var keys = npc_manager.enemy_data_dict.keys() enemy_ui.select_enemy(keys[0]) else: print("No NPC's Available") func select_next_enemy(): var keys = npc_manager.enemy_data_dict.keys() var current_index = keys.find(enemy_ui.selected_enemy_key) if current_index != -1: var next_index = (current_index + 1) % keys.size() enemy_ui.select_enemy(keys[next_index])