This is the code:
Code: Select all
local function Basic_detection(UBS_table)
for UBS_var_1 = 1, 1000000 do
game.player.print("first part")
if UBS_table[UBS_var_1] then
game.player.print("second part")
if UBS_table[UBS_var_1].neighbours == nil then
game.player.print("fifth part")
game.player.print("UBS has detected a disconnected basic underground belt at: " .. "X = " .. tostring(UBS_table[UBS_var_1].position.x) .. ", Y = " .. tostring(UBS_table[UBS_var_1].position.y) )
else
--a neigbour has been detected
game.player.print("third part")
game.player.print(tostring(game.tick))
end
game.player.print("fourth part")
else
game.player.print("Detection has stopped, above this message you can see all the hits" .. tostring(UBS_var_1))
break
end
end
end
Code: Select all
local function BuildTableBTPBTG()
UBS_table_BTBTG = game.get_surface(1).find_entities_filtered{area = {{-10000, -10000}, {10000, 10000}}, name= "basic-transport-belt-to-ground"}
game.player.print("UBS: Table has been built, checking for non connected underground belts now.")
Basic_detection(UBS_table_BTBTG)
end
The created table then gets passed on to the Basic_detection function that is in the code block on top.
That all works. BUT: this does not work:
I check if UBS_table[UBS_var_1].neighbours == nil, but this seems to never be the case, even IF it does not have any connection. so according to the wiki it should be nil then.
But, like I said, the thing never returns nil, like never never.When called on an underground transport belt, this is the other end of the underground belt connection, or nil if none.
There are some parts added in between printing some messages, most of those will be stripped as they are only for debugging purposes. If you wish to run the code yourselves, This code snippet contains it all:
Code: Select all
require("defines")
local function Basic_detection(UBS_table)
for UBS_var_1 = 1, 1000000 do
game.player.print("first part")
if UBS_table[UBS_var_1] then
game.player.print("second part")
if UBS_table[UBS_var_1].neighbours == nil then
game.player.print("fifth part")
game.player.print("UBS has detected a disconnected basic underground belt at: " .. "X = " .. tostring(UBS_table[UBS_var_1].position.x) .. ", Y = " .. tostring(UBS_table[UBS_var_1].position.y) )
else
--a neigbour has been detected
game.player.print("third part")
game.player.print(tostring(game.tick))
end
game.player.print("fourth part")
else
game.player.print("Detection has stopped, above this message you can see all the hits" .. tostring(UBS_var_1))
break
end
end
end
local function Fast_detection(UBS_table)
for UBS_var_1 = 1, 1000000 do
if UBS_table.UBS_var_1 then
if UBS_table.UBS_var_1.neighbours then
--a niegbour has been detected
else
game.player.print("UBS has detected a not-connected fast underground belt at: " .. "X = " .. tostring(UBS_table.UBS_var_1.position.x) .. "Y = " .. tostring(UBS_table.UBS_var_1.position.y) )
end
else
break
end
end
end
local function Express_detection(UBS_table)
for UBS_var_1 = 1, 1000000 do
if UBS_table.UBS_var_1 then
if UBS_table.UBS_var_1.neighbours then
--a niegbour has been detected
else
game.player.print("UBS has detected a not-connected express underground belt at: " .. "X = " .. tostring(UBS_table.UBS_var_1.position.x) .. "Y = " .. tostring(UBS_table.UBS_var_1.position.y) )
end
else
break
end
end
end
--]]
local function BuildTableBTPBTG()
UBS_table_BTBTG = game.get_surface(1).find_entities_filtered{area = {{-10000, -10000}, {10000, 10000}}, name= "basic-transport-belt-to-ground"}
game.player.print("UBS: Table has been built, checking for non connected underground belts now.")
Basic_detection(UBS_table_BTBTG)
end
local function BuildTableFTPBTG()
UBS_table_FTBTG = game.surfaces["nauvis"].find_entities_filtered{area = {{-100000, -100000}, {100000, 100000}}, name= "fast-transport-belt-to-ground"}
Fast_detection(UBS_table_FTBTG)
end
local function BuildTableETPBTG()
UBS_table_ETBTG = game.surfaces["nauvis"].find_entities_filtered{area = {{-100000, -100000}, {100000, 100000}}, name= "express-transport-belt-to-ground"}
Express_detection(UBS_table_ETBTG)
end
script.on_event(defines.events.on_tick, function(event)
if not UBS_var_dns then
if not UBS_var2 then
UBS_var2 = 0
end
if UBS_var2 == 60 then
if not game.player.gui.left.UBS_frame then
game.player.gui.left.add{type = "frame", name = "UBS_frame", caption = "Do you want to check for non-connected underground belt?", direction = "vertical"}
game.player.gui.left.UBS_frame.add{type = "label", name = "UBS_lbl_warning", caption = "Warning, this might take longer than 2 minutes, depending on the speed of your machine."}
game.player.gui.left.UBS_frame.add{type = "button", name = "UBS_button_basic", caption = "Check basic belts"}
game.player.gui.left.UBS_frame.add{type = "button", name = "UBS_button_fast", caption = "Check fast belts"}
game.player.gui.left.UBS_frame.add{type = "button", name = "UBS_button_express", caption = "Check express belts"}
game.player.gui.left.UBS_frame.add{type = "button", name = "UBS_button_not", caption = "Do not Check"}
end
else
UBS_var2 = UBS_var2 + 1
end
end
end)
script.on_event(defines.events.on_gui_click, function(event)
if event.element.name == "UBS_button_basic" then
game.player.gui.left.UBS_frame.destroy()
UBS_var_dns = true
BuildTableBTPBTG()
elseif event.element.name == "UBS_button_fast" then
game.player.gui.left.UBS_frame.destroy()
UBS_var_dns = true
BuildTableFTPBTG()
elseif event.element.name == "UBS_button_express" then
game.player.gui.left.UBS_frame.destroy()
UBS_var_dns = true
BuildTableETPBTG()
elseif event.element.name == "UBS_button_not" then
game.player.gui.left.UBS_frame.destroy()
UBS_var_dns = true
end
end)