Question: How to get properties off of sensed items?

Hi ok so I’ve posted a few questions in the past few days and I’m making progress but more questions seem to arise. So I have this situation where the player hits an item and adds it to his inventory, but to avoid naming conflicts I want him to get the name of the item off of a property and not the name of the object itself. I got some help from BluePrintRandom to set up the inventory system. Here is my current code:



import bge


def main():
    
    #The reason for this is because the player box is for collision, the player brain is an empty to handle
    #logic. Idk if this is the best way to do this and I might change it.
    scene = bge.logic.getCurrentScene()
    player = scene.objects['playerBrain']
    
    cont = bge.logic.getCurrentController()
    box = cont.owner
    
    #Actually a collision sensor with a big box surrounding the item to simulate being in range because I couldn't get it
    #to work with a near sensors
    near = cont.sensors['nearWeap']
    #Just pressing the "E" key
    action = cont.sensors['e']
    
    if near.positive and action.positive:
        
        item = near.hitObject
        
        #This is the problem. All the console says is "KeyError: 'itemName'    I am sure that that is the correct spelling
        itemName = item.attrDict['itemName']
        
        #inventory is already a list, this part works fine
        player['inventory'].append(itemName)
        
        #A debug property
        box['invWorks'] = True
 
main() 



Thanks a bunch

[Edit] I tried this line: item[‘itemName’] = “Test” to change the property and I got no error but it didn’t change the name…

[Edit #2] And then I added this: box[‘equipped’] = item[‘itemName’] and it changed to “Test” but itemName still displayed as “axe”! WAT?!

[Edit #3] Final edit, probably. I got rid of item[‘itemName’] = “Test” and it didn’t work. I guess the property isn’t initialized or something. Is it creating a new instance or something?

[Edit #4] Solved lol sorry.

Ok this is really trippy. I run the game once, one item works the other doesn’t. I run it again, no changes, and it doesn’t work.

Ok I think I figured out what the problem is… I fell dumb now lol. I had a box for the collision sensor around the item which was static ghost so it still triggered the collision sensor but gave an error since it didn’t have the property itemName. Sorry for all the trouble