LuaEntity.drop_target and LuaEntity.pickup_target of inserters are nil when building inserters in on_built_entity. Even though the entities to pickup from/drop of to are already placed.
You can still still get the same behaviour by inserter.surface.find_entities_filtered{position = inserter.drop_position}. So not a big problem.
And probably related
The LuaTransportLine.input_lines and LuaTransportLine.output_lines of the transport lines of the transport belt the inserter drops to/picks up from sometimes return as empty lists when building the inserter. They aren't empty when building the belts.
To recreate
in control.lua
Code: Select all
script.on_event(defines.events.on_built_entity, function(event)
if event.created_entity.type == "inserter" then
local inserter = event.created_entity
print("Building an inserter at", inserter.position.x, inserter.position.y)
print("This one shouldn't be nil on creation if the targets are there:",
inserter.drop_target, inserter.pickup_target)
local drop_entity = inserter.surface.find_entities_filtered{
position = inserter.pickup_position, --or inserter.drop_position
}
if drop_entity and #drop_entity == 1 then
local belt = drop_entity[1]
if belt and belt.type == "transport-belt" then
print("Amount of input lines 1:", #belt.get_transport_line(1).input_lines)
print("Amount of output lines 1:", #belt.get_transport_line(1).output_lines)
print("Amount of input lines 2:", #belt.get_transport_line(2).input_lines)
print("Amount of output lines 2:", #belt.get_transport_line(2).output_lines)
end
end
elseif event.created_entity.type == "transport-belt" then
local belt = event.created_entity
print("Building a transport belt at", belt.position.x, belt.position.y)
print("Amount of input lines 1:", #belt.get_transport_line(1).input_lines)
print("Amount of output lines 1:", #belt.get_transport_line(1).output_lines)
print("Amount of input lines 2:", #belt.get_transport_line(2).input_lines)
print("Amount of output lines 2:", #belt.get_transport_line(2).output_lines)
end
end)

The belts correctly indicate that the transport_lines of previous belts are connected when #output_lines or #input_lines are 1. But when building the inserter and calling it on the same exact entity, the input/output_lines are sometimes empty.
Sometimes? Yes. It's inconsistent.
Sometimes it does give the correct number of input_lines/output_lines. (I can't find a pattern on when this is, might have to retry a few times).
But then repetitively deleting and rebuilding the inserter will eventually turn it all to 0, but not back to 1.
Here is the output of where I first built 3 belts, then an inserter pickup up from the belt, deleted the inserter, and rebuilt it:
Code: Select all
Building a transport belt at 5.5 0.5
Amount of input lines 1: 0
Amount of output lines 1: 0
Amount of input lines 2: 0
Amount of output lines 2: 0
Building a transport belt at 5.5 2.5
Amount of input lines 1: 0
Amount of output lines 1: 0
Amount of input lines 2: 0
Amount of output lines 2: 0
Building a transport belt at 5.5 1.5
Amount of input lines 1: 1
Amount of output lines 1: 1
Amount of input lines 2: 1
Amount of output lines 2: 1
Building an inserter at 4.5 1.5
This one shouldn't be nil on creation if the targets are there: nil nil
Amount of input lines 1: 1
Amount of output lines 1: 1
Amount of input lines 2: 1
Amount of output lines 2: 1
Building an inserter at 4.5 1.5
This one shouldn't be nil on creation if the targets are there: nil nil
Amount of input lines 1: 0
Amount of output lines 1: 0
Amount of input lines 2: 0
Amount of output lines 2: 0
I haven't tested it with underground belts/splitters/loaders/drills, but I can imagine the same thing happens there
I'm trying to figure out to which transport line an inserter inserts items to. Which is fine as it's usually top right, except for that one exception where it inserts top left, for which I need to check the input_lines of the transportline.
Related interface request for that: viewtopic.php?t=59076