My 'canister' is copied from the car prototype. This gives it other qualities I need, such as mobility, disabled collision and being drawn under other objects. As I need canisters to move, I can't set them to inactive.
Right now my solution is to look for inserters that target a canister and set their target to nil. This is very slow, and doesn't even really work as the inserters will find a target again right away. I tried setting the inserters inactive (and reactivating the next tick), but this gave the same result, and also slow. So I would have to check if the canister was far enough away to turn the inserter back on again - even slower.
Code: Select all
function test_disable_can_inserters(surface, event)
-- find all inserters of all kinds
local all_entities = surface.find_entities()
local inserters = {}
for _, entity in ipairs(all_entities) do
if string.find(entity.name, "nserter") then
table.insert(inserters, entity)
end
end
for _, inserter in pairs(inserters) do
if inserter.drop_target then
if inserter.drop_target.name == "canister" then
inserter.drop_target = nil
end
end
if inserter.pickup_target then
if inserter.pickup_target.name == "canister" then
inserter.pickup_target = nil
end
end
end
end