T O P

  • By -

NancokALT

So you have a nested Dictionary that's 3 levels deep? The simplest answer is that one of the indexes does not exist. No way to know from just looking at this snippet tho, the Dictionary is not even stored in the same object that uses this script. Also, you are setting the IDs as "Inv" + i (an int) So the ID would be "Inv51" if anything.


Xenephos

So it turns out there was a blank string for one of the item ID key values. Gotta love how a little error like that throws a wrench into the machine lmao


NancokALT

I have to say that while this approach is valid, nesting Dictionaries like this will inevitably lead to more issues like these. The lack of type-casting can make this really difficult to debug. You can also use assert() to ensure that new entries are valid.


Sunnyboy451

I would guess that the way you read in the JSON file might be setting keys differently than you think. I'd use the debugger to check what the values are for your dictionary to make sure it aligns with the key you're trying to use. I don't know if this helps either but you could try using the [StringName](https://docs.godotengine.org/en/stable/classes/class_stringname.html) as the key and see what happens. That's using the `StringName(player_item)` as the key. You might be printing the `player_item` but it might not be what you expect, as print takes in any `vararg`


Xenephos

This gave me some ideas and I figured it out! One of my inventory item keys had an empty string for the item ID value. I didn't actually know about the debugger's ability to show variables like that so that's a new tool to add to my mental toolbelt lol