0 votes

Hello! I decided to study the inventory system using this demo:
https://github.com/szechset/PC-Inventory-Demo

I decided to make an item generator in order to delve a little more into this system and faced the fact that I needed a container for the generator, similar to the inventory.
I added code to generate slots and items from the inventory example and ran into the problem that Godot reads both dictionaries

Inventory:

func _ready():
if !dictionary_inv.itemDictionary.empty():
    for item in dictionary_inv.itemDictionary:
        var itemType = dictionary_inv.itemDictionary[item].itemType
        var itemName = dictionary_inv.itemDictionary[item].itemName
        var itemIcon = dictionary_inv.itemDictionary[item].itemIcon
        var itemStack = dictionary_inv.itemDictionary[item].itemStack
        var itemStackMax = dictionary_inv.itemDictionary[item].itemStackMax
        var itemStackValue = dictionary_inv.itemDictionary[item].itemStackValue
        var itemEq = dictionary_inv.itemDictionary[item].itemEq
        itemList.append(ItemClass.new(itemType, itemName, itemIcon, itemStack, itemStackMax, itemStackValue, itemEq, null))


for i in range(inventorySize):
    var slot = SlotClass.new(i, 'none')
    slotList.append(slot)
    $inv_ui/zpa/Container/GridContainer.add_child(slot)
    if !dictionary_inv.itemDictionary.empty():
    var x = 0
    var itemDelete = Array()
    for i in dictionary_inv.itemDictionary:
        if i < inventorySize:
            if dictionary_inv.itemDictionary[i].itemStack:
                if dictionary_inv.itemDictionary[i].itemStackValue > dictionary_inv.itemDictionary[i].itemStackMax:
                    itemDelete.append(i)
                    itemList.remove(x)
                else:
                    slotList[i].setItem(itemList[x])
                    slotUsed.append(itemList[x].itemIndex)
                    x += 1
            else:
                slotList[i].setItem(itemList[x])
                slotUsed.append(itemList[x].itemIndex)
                x += 1
        elif i >= inventorySize and i < (inventorySize + eqSize):
            if dictionary_inv.itemDictionary[i].itemEq.has(slotList[i].slotEq):
                slotList[i].setItem(itemList[x])
                x += 1
            elif !dictionary_inv.itemDictionary[i].itemEq.has(slotList[i].slotEq):
                itemDelete.append(i)
                itemList.remove(x)
        else:
            itemDelete.append(i)
            itemList.remove(x)
    for i in itemDelete:
        dictionary_inv.itemDictionary.erase(i)
    slotUsed.sort()

Duplicate lines for the item container:

    if !allItemn.allItem.empty():
    for item in allItemn.allItem:
        var itemType = allItemn.allItem[item].itemType
        var itemName = allItemn.allItem[item].itemName
        var itemIcon = allItemn.allItem[item].itemIcon
        var itemStack = allItemn.allItem[item].itemStack
        var itemStackMax = allItemn.allItem[item].itemStackMax
        var itemStackValue = allItemn.allItem[item].itemStackValue
        var itemEq = allItemn.allItem[item].itemEq
        itemList.append(ItemClass.new(itemType, itemName, itemIcon, itemStack, itemStackMax, itemStackValue, itemEq, null))

for j in range(creative):
    var slot = SlotClass.new(j, 'none')
    slotList.append(slot)
    $creative_container/ScrollContainer/GridContainer.add_child(slot)

if !allItemn.allItem.empty():
    var x = 0
    var itemDelete = Array()
    for j in allItemn.allItem:
        if j < creative:
            if allItemn.allItem[j].itemStack:
                if allItemn.allItem[j].itemStackValue > allItemn.allItem[j].itemStackMax:
                    itemDelete.append(j)
                    itemList.remove(x)
                else:
                    slotList[j].setItem(itemList[x])
                    slotUsed.append(itemList[x].itemIndex)
                    x += 1
            else:
                slotList[j].setItem(itemList[x])
                slotUsed.append(itemList[x].itemIndex)
                x += 1
        elif j >= creative and j < (creative):
            if allItemn.allItem[j].itemEq.has(slotList[j].slotEq):
                slotList[j].setItem(itemList[x])
                x += 1
            elif !allItemn.allItem[j].itemEq.has(slotList[j].slotEq):
                itemDelete.append(j)
                itemList.remove(x)
        else:
            itemDelete.append(j)
            itemList.remove(x)
    for j in itemDelete:
        allItemn.allItem.erase(j)
    slotUsed.sort()

But items are loaded into both inventory and container using 2 dictionaries at once.

in Engine by (71 points)

I don't think your question is understandable. May you colaborate? Put some gif or describe better your issue, I don't get it really.

In general, this system only works with one dictionary, and when I try to create 2 different dictionaries for inventory and chest, an error occurs when all dictionaries are combined and the items overlap.
The screenshot shows that the item appeared in the place of another object: https://prnt.sc/ugllxj

Willing to send code for inventory scene? Code here is mess (wrong formating?) and I am not sure what in the code is "possible working if.." and what's "this is definitely wrong".

--
btw, I've read the github code you've got inspired from carefully, must say it's utterly bad code that I can't recommend for learning.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.