Jump to content

container usespecificslotsforitems , is it working as intended?


Serpens
  • Pending

Hello,

I'm currently making a container that should have a tool in slot 1, while all other slots are free.
So I have an itemtestfn that checks for slot 1 + if item has any actionid tool Tag and I set usespecificslotsforitems to true.
This works in the way that slot 1 is always blocked this way, also when slot from GiveItem is initially nil.

But for other items that wont go into slot 1 it does not work well while slot is initially nil. Since slot 1 is blocked, the GetSpecificSlotForItem function always returns "slot 2". But if this slot is already occupied with a full stack or a non stackable item, the given item is completely refused, although slot 3 to x are still empty. Only if in slot 3 to x is a non-full stackable of the given item, it will succesfully add the item to this stack. But if it is a full stack, it will again not work.

Example:
Slot 1 is blocked for tools.
Slot 2 is occupied a full stack or a non stackable item.
Slot 3 to x are empty.
Now try to give the container any item (with slot initially nil), it wont accept it or drop it, although there is more than enough space.

Example 2:
Slot 1 is blocked for tools.
Slot 2 is occupied a full stack or a non stackable item.
Slot 3 is empty
Slot 4 is a half stack of cutgrass
Slot 5 to x are empty.
Now try to give him 1 cutgrass and it will successfully to to slot 4.


So I'm sure it is not yet working as intended.
I guess the GetSpecificSlotForItem should also take into account if the slot is already occupied or you need to add any other checks, to prevent this kind of problem.

A simple fix for GetSpecificSlotForItem I wrote could be:

function Container:GetSpecificSlotForItem(item)
    if item~=nil and self.usespecificslotsforitems and self.itemtestfn ~= nil then
        local iteminslot = nil
        for i = 1, self:GetNumSlots() do
            iteminslot = self:GetItemInSlot(i)
            if iteminslot==nil or (iteminslot.prefab == item.prefab and iteminslot.skinname == item.skinname and self.acceptsstacks and iteminslot.components~=nil and iteminslot.components.stackable~=nil and not iteminslot.components.stackable:IsFull()) then
                if self:itemtestfn(item, i) then
                    return i
                end
            end
        end
    end
end

so basically only adding one line to check the item in the slot, so if it is occupied or if there is a stackable item we can stack on.
It seems to work prefectly fine and I think this should also cause no issue for warly.


Steps to Reproduce
see description



User Feedback


There are no comments to display.



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...