inventory system for BGE

inventory system for BGE
!!!(I want to remove the item from the slot for another item can occupy the empty space)!!!:slight_smile:

(player commands)
import bge:cool:

cont = bge.logic.getCurrentController()
cena = bge.logic.getCurrentScene()
nearItem = cont.sensors[‘nearItem’]

for i in range(4):
if bge.logic.globalDict[‘inventario’][i] == None:
try:
bge.logic.globalDict[‘inventario’][i] = nearItem.hitObject
slot = cena.objects[‘item’+str(i+1)]
nearItem.hitObject.position = slot.position
nearItem.hitObject.localScale = slot.localScale
nearItem.hitObject.setParent(slot)
except:
pass
break


inventory commands

import bge

bge.logic.globalDict[‘inventario’] = 4 * [None]

Please use code tags when posting code snippets.

Is it something like that that you want?


def replaceItem(slot, replaceingItem):
    replacedItem = slot.releaseItem()
    slot.takeItem(replaceingItem)
    return replacedItem 

or in another form:


def replaceItem(slot, replaceingItem):
    replacedItem = releaseItem(slot)
    takeItem(slot, replaceingItem)
    return replacedItem