It doesn't seem to work. I have the following function, which is intended to return true if the pipe is an end pipe (has only one connection.)
Code: Select all
function weartear.is_end_pipe(entity)
local result = false
local neighbours = entity.neighbours
if neighbours then
local the_real_size = 0
game.print("size of this thing is " .. #neighbours)
for i=#neighbours,1, -1 do
game.print("examining neighbor#"..i)
if neighbours[i] then
game.print("neighbor#" .. i .. " is real")
if neighbours[i].valid then
game.print("neighbor#" .. i .. " is a " .. neighbours[i].name)
the_real_size = the_real_size + 1
end
else
game.print("neighbor#" .. i .. " was nil.")
end
end
if the_real_size == 1 then result = true end
end
return result
end
Example: A pipe connected to a tank and another pipe reports only one neighbor, the tank. A horizontal pipe connected on either side reports 4 neighbors: 1 pipe and 3 "nils". I had to actually iterate through all the neightbors in the table and tabulate "the_real_size" by nil checking every item in the table, but even that's not working because in alot of cases it doesn't detect all the neighbors. eg: a pipe with 2 other pipes connected only returns 1 neighbor, giving a false positive. It's very inconsistent.
Am I looking at this wrong? Or is it a bug?