feverdog
Active Member
- Joined
- Mar 10, 2008
- Messages
- 229
- Reaction score
- 36
Hello guys, I was doing a function for getting all containers inside a parent container have but it seems that it only gets backpacks inside the main backpack and it doesn't do the recursion towards the backpacks inside the backpacks inside the main backpack, and so on.. is there a catch I do not know here??
Code:
function jlibs.getAllContainers(container)
local containers = {}
function getContainers(container)
if(isItemContainer(container.itemid)) then
table.insert(containers, container)
end
items = jlibs.getContainerItems(container)
if not (items) then
return
end
for k, v in pairs(items) do
if (isItemContainer(v.itemid)) then getContainers(v) end
end
return containers
end
return getContainers(container)
end