• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua check items house

Fortera Global

Intermediate OT User
Joined
Nov 20, 2015
Messages
1,180
Solutions
2
Reaction score
117
this script is for check items inside all houses but something is wrong, no checking all houses, can someone help?

Lua:
 local houses = Game.getHouses()
        local found = false       
        for i = 1, #houses do
            local house = houses[i]
            local house_tiles = house:getTiles()
            local itemInHouse = 0
            for x = 1, #house_tiles do
                local tile = house_tiles[x]
                local items = tile:getItems()
                for y = 1, #items do
                    local item = items[y]
                    if item:isContainer() then
                        itemInHouse = itemInHouse + searchInContainer(item, item_id)
                    elseif item:getId() == item_id then
                        itemInHouse = itemInHouse + item:getCount()
                    end
                end
            end
         end
 
Solution
Before you use a value you think might be a table you must validate if it is indeed a table and that it contains values.
Lua:
local houses = Game.getHouses()
if houses and next(houses) then
    local found = false   
    for i = 1, #houses do
        local house = houses[i]
        local house_tiles = house:getTiles()
        local itemInHouse = 0
        if house_tiles and next(house_tiles) then
            for x = 1, #house_tiles do
                local tile = house_tiles[x]
                local items = tile:getItems()
                if items and next(items) then
                    for y = 1, #items do
                        local item = items[y]
                        if item:isContainer() then...
Before you use a value you think might be a table you must validate if it is indeed a table and that it contains values.
Lua:
local houses = Game.getHouses()
if houses and next(houses) then
    local found = false   
    for i = 1, #houses do
        local house = houses[i]
        local house_tiles = house:getTiles()
        local itemInHouse = 0
        if house_tiles and next(house_tiles) then
            for x = 1, #house_tiles do
                local tile = house_tiles[x]
                local items = tile:getItems()
                if items and next(items) then
                    for y = 1, #items do
                        local item = items[y]
                        if item:isContainer() then
                            itemInHouse = itemInHouse + searchInContainer(item, item_id)
                        elseif item:getId() == item_id then
                            itemInHouse = itemInHouse + item:getCount()
                        end
                    end
                end
            end
        end
    end
end
I would run this script step by step to determine if i was getting the right results and counter anything not interested in.
 
Solution
Back
Top