Invalid access to property or key '<null>' on base object of type dictionary

Godot Version

4.3 stable Windows 11

Question

I have an autoload script meant to serve as a database of item information. Here is a bit of code from it:

const UPGRADES = {
	"hammer1": {
		"icon" : ###icon path
		"displayname": "Hammer",
		"description": "Short-ranged swing for 3x base damage.",
		"flavor": " ",
		"level": 1,
		"maxlevel": 5,
		"prerequisite": [],
		"type": "physical"
	}
}

And then, in my player script, I have this code:

@onready var itemPanel = get_node("%ItemSelection")
@onready var upgradeOptions = get_node("%UpgradeOptions")
@onready var itemOptions = preload("res://Utility/item_option.tscn")

func openchest():
                while options < 4 :
		var option_choice = itemOptions.instantiate()
		upgradeOptions.add_child(option_choice)
		options += 1

In my item_option scene, I have this scene tree and code:
image

func _ready():
	if item == null :
		item == "hammer1"
	lblName.text = UpgradeDb.UPGRADES[item]["displayname"]
	lblDescription.text = UpgradeDb.UPGRADES[item]["description"]
	lblDamagetype.text = UpgradeDb.UPGRADES[item]["type"]
	lblFlavor.text = UpgradeDb.UPGRADES[item]["flavor"]
	itemIcon = load(UpgradeDb.UPGRADES[item]["icon"])

But when openchest() is run, I get the error written in the title, pointing to the line lblName.text = UpgradeDb.UPGRADES[item]["displayname"]. Besides item_option.tscn, everything else runs with no issues.

Do I not understand dictionaries? Is my syntax wrong? Why is it returning null? Any help is appreciated.

I think you put an equal sign too much:

func _ready():
	if item == null :
		item = "hammer1"
	lblName.text = UpgradeDb.UPGRADES[item]["displayname"]
	lblDescription.text = UpgradeDb.UPGRADES[item]["description"]
	lblDamagetype.text = UpgradeDb.UPGRADES[item]["type"]
	lblFlavor.text = UpgradeDb.UPGRADES[item]["flavor"]
	itemIcon = load(UpgradeDb.UPGRADES[item]["icon"])

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.