Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Engi of Stupidity |
I’ve been trying to make a clicker game that has survival and fighting mechanics. I store data about the enemies in a JSON file like this:
{
"0": {
"Name": "Tree",
"Area": "Tree",
"AmountKilled": 0,
"Damage": 0,
"BaseHP": 100,
"Fatigue": 20,
"DroppedItem": "Wood"
}
}
What i tried to do in a script is get the name and dropped item of the enemy by having:
var EnemyId = 0
var EnemyName = JsonLoader.EnemyData[str(EnemyId)]["Name"]
var DroppedItem = JsonLoader.EnemyData[str(EnemyId)]["DroppedItem"]
this however gives “Invalid get index ‘0’ (on base: ‘Dictionary’).” as an error when i try to run it.
Here’s the JsonLoader too in case it’s causing the problem:
extends Node
var EnemyData: Dictionary
func _ready():
EnemyData = LoadData("res://Data/EnemyData.json")
print(EnemyData)
func LoadData(FilePath):
var JSONData
var FileData = File.new()
FileData.open(FilePath, File.READ)
JSONData = JSON.parse(FileData.get_as_text())
FileData.close()
return JSONData.result