function somekindofsearch(item)
declare main list
normal container search
if items[i]:isContainer() then
local sublist = somekindofsearch(items[i])
for k, v in pairs(sublist) do
insert results to main list
end
end
return some list
end
Yes, but I wanna know if there are easiest ways, but I think recursive is the only solution for this problem haha. Thanks!You will have to make a recursive function.
Thanks! I'm gonna look.I do exactly that in this function.
I'm sure you can modify it to fit your needs.
![]()
TFS 1.4 getListOfContainerItems
Finds all of the items in a container, and returns it as a table. function getListOfContainerItems(container) if not container:isContainer() then return false end local containers, items = {}, {} table.insert(containers, container) while #containers > 0 do...otland.net
Yes, pratically it's necessary to do a recursive function as Boy67 said. I wanted to know if there was a easiest ways. But I will do recursive function! Thanks!The main concept is to
- store results in a list
- put the list in function output
- call the same function on subcontainer to get results from it
- merge subcontainer search results with main (or parent) list
example:
(not actual code, just explaination how to do that)
Code:function somekindofsearch(item) declare main list normal container search if items[i]:isContainer() then local sublist = somekindofsearch(items[i]) for k, v in pairs(sublist) do insert results to main list end end return some list end
repeat loop and only insertsfunction Container:getItems()
local index, containers, items = 0, {self}, {}
repeat
index = index +1
local container = containers[index]
for i = 0, container:getSize() - 1 do
local item = container:getItem(i)
items[#items +1] = item
if item:isContainer() then
containers[#containers +1] = item
end
end
until #containers <= index
return items
end
container:getItems(true) to get all the elements of all the containers including the same containersThanks! This is similar the code of Xikini in topic: TFS 1.4 getListOfContainerItems (https://otland.net/threads/tfs-1-4-getlistofcontaineritems.278178/)Here is another example that uses arepeatloop and only inserts
¡This method always is recursive!
LUA:function Container:getItems() local index, containers, items = 0, {self}, {} repeat index = index +1 local container = containers[index] for i = 0, container:getSize() - 1 do local item = container:getItem(i) items[#items +1] = item if item:isContainer() then containers[#containers +1] = item end end until #containers <= index return items end
Although if you are in TFS 1.4+ you should already be able to use the Container.getItems method by default that already come from the sources
This method has a single optional parameter and it is a boolean,container:getItems(true)to get all the elements of all the containers including the same containers