Invalid get index '0' (on base: 'Dictionary').

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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")
func LoadData(FilePath):
	var JSONData
	var FileData =, File.READ)
	JSONData = JSON.parse(FileData.get_as_text())
	return JSONData.result
:bust_in_silhouette: Reply From: samjmiller

Usually an “invalid get index” means you’re not calling the file correctly, which is often an issue with the filepath or node spelling.

So, it could be that in EnemyData = LoadData("res://Data/EnemyData.json") something is in the wrong folder, or that there’s a misspelling somewhere in your code routing to the Dictionary - often something as simple as a capitalization error (Json for JSON, or vice versa).

Hope this helps!