Item Dropping System Help?

Hey everyone, so I’m trying to make a dropping system (as in from an inventory) in which an item spawner is spawned at the player’s ‘feet’. The way that my item spawners work is they are a simple box with a property ‘itemName’. Using this property I can access the properties of the actualy items, found in layer #2. So, if the player selects an item from his inventory and drops it, it adds an object ‘itemSpawner’ from layer #2 with the property ‘itemName’ and sets it equal to the selected item, so that the player can pick up the item again. It wasn’t working; I was getting the error of something along the lines of ‘key “” does not exist’ when the player tried to pick the item up again (Worth mentioning; it worked until I dropped like four items at once so they all spawned in one spot, then it stopped working after I re-ran the game, even with only one added spawner.) I made ‘itemName’ a debug property, and turns out it never changed from not having a value. I’m guessing if you add an object you can’t change its properties. This is a huge issue for me since the entire item system was supposed to rely on being able to do this. Are there any alternatives, or am I just missing something possibly?

Here’s the code that adds the spawner:

droppedSpawner = scene.addObject(scene.objectsInactive['itemSpawner'], box, 0)
droppedSpawner['itemName'] = inv['selectedItem']

But wouldn’t this create something sort of like a “new instance of the object” ‘itemSpawner’?


So you want to be able to pick up an item you have dropped while having an place holder object on the floor?

Move with A & D
Drop with space
Pick up with walking into / colliding


drop.blend (544 KB)

ok, so a game item = gameObject = key

name = name of a item

I think that you are calling an item that has been deleted,

lets see the code for the pick up system?

also do print(own[‘itemSelected’])

before the item spawn?

@BluePrintRandom I know that the property isn’t chaning so it’s not that I’m calling an object that doesn’t exist, (well technically I am because there’s no object without a name), it’s just that the value of itemName is empty. Still, here’s the code for picking items up (Note, these are kind of all in different locations within the script):

def addItem(item):
        if in inv[item['section']]:
            inv[item['section'] + 'Int'][inv[item['section']].index(] += 1
            player['weight'] += item['weight']
            inv[item['section'] + 'Int'].append(1)
            player['weight'] += item['weight']

#Pick Up Items
    if near.positive and action.positive: #near is now a ray sensor, used to be collision
        spawner = near.hitObject
        item = scene.objectsInactive[spawner['itemName']]
        if player['weight'] + item['weight'] < player['maxWeight']:

@VegetableJuiceF I looked at your file and that’s exactly what I want to do I think (except that I have an item that’s a placeholder and another item that’s like the actual item), except yours works and mine doesnt lol

droppedSpawner = scene.addObject(scene.objectsInactive['itemSpawner'], box, 0)
droppedSpawner['itemName'] = inv['selectedItem']

lets see what your setting it as?

I have a feeling inv[‘selectedItem’] is not being set correctly?

I think I know what the problem is. Above the spawner I have my ‘removeItem’ function which gets rid of selectedItem. I’ll try to make it so that the removeItem function goes after the creation of the spawner. Sorry again for all the trouble when I just overlook something that I could have fixed just by looking at the code again :frowning:

Yeah lol oh my gosh it works 100% just tried it. Thanks so much again!

N/p, :smiley:

Merry blending!