Running recursive for loops is not what i want to do in on_tick handling just to get a complete list of signals.
It's a shame we don't have defines.wire_type.all

Code: Select all
function GetCircuitValues(entity)
local greenWire = entity.get_circuit_network(defines.wire_type.green)
local redWire = entity.get_circuit_network(defines.wire_type.red)
local items = {}
if greenWire then
for _, v in pairs (greenWire.signals) do
if v.signal.type == "item" then
items[v.signal.name] = v.count
end
end
end
if redWire then
for _, v in pairs (redWire.signals) do
if v.signal.type == "item" then
if items[v.signal.name] ~= nil then
items[v.signal.name] = items[v.signal.name] + v.count
else
items[v.signal.name] = v.count
end
end
end
end
return items
end
That's what the game doesOptera wrote:... as I can't imagine every combinator doing these two for each loops every tick.
Is that why feeding the whole content of the logistic network from roboports into several combinators causes network update to take noticeable more time?Rseding91 wrote:That's what the game doesOptera wrote:... as I can't imagine every combinator doing these two for each loops every tick.
Code: Select all
local red , green
= defines.wire_type.red, defines.wire_type.green
function GetCircuitValues( entity )
local items, wire
= {} , entity.get_circuit_network( green )
if wire then
for _, data in pairs( wire.signals ) do
if data.signal.type == "item" then
items[data.signal.name] = data.count
end
end
end
wire = entity.get_circuit_network( red )
if wire then
local value
for _, data in pairs (wire.signals) do
if data.signal.type == "item" then
value = items[data.signal.name]
items[data.signal.name] = value and (value + data.count) or data.count
end
end
end
return items
end