Godot Version
4.3 stable Windows 11
Question
I have this code that is supposed to add graphic slots with item sprites in them:
for slotnumber in weapon_slots :
var slot_graphic = TextureRect.new()
slot_graphic.texture = load("res://Textures/GUI/inventory_slot.png")
weapon_inventory.add_child(slot_graphic)
print(collected_upgrades["weapon"][slotnumber].keys())
if not collected_upgrades["weapon"][slotnumber].keys().size() == 0 :
var item_graphic = TextureRect.new()
item_graphic.texture = load(UpgradeDb[collected_upgrades["weapon"][slotnumber][0]]["icon"])
print(UpgradeDb[collected_upgrades["weapon"][slotnumber].keys()[0]]["icon"])
slot_graphic.add_child(item_graphic)
But the keys()
function just returns an empty array everytime, even though this is what collected_upgrades looks like:
{ "weapon": { 0: { "hammer": { "level": 1 } }, 1: { }, 2: { }, 3: { }, 4: { }, 5: { }, "nonslot": { } }, "passive": { 0: { }, 1: { }, 2: { }, 3: { }, 4: { }, 5: { }, "nonslot": { } } }
As far as I can tell, collected_upgrades["weapon"][slotnumber].keys()
should return an array with “hammer”, and then empty arrays for the remaining slots for the rest of the for loop. But that doesn’t seem to be what’s happening. Do I just not understand dictionaries? Is my syntax wrong? This is giving me a headache, any help is appreciated.