This is the version I was using up until now.
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
items[v.signal.type..","..v.signal.name] = v.count
end
end
if redWire then
for _, v in pairs (redWire.signals) do
if items[v.signal.type..","..v.signal.name] ~= nil then
items[v.signal.type..","..v.signal.name] = items[v.signal.type..","..v.signal.name] + v.count
else
items[v.signal.type..","..v.signal.name] = v.count
end
end
end
return items
end
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 i=1, #greenWire.signals do
local type = greenWire.signals[i].signal.type
local name = greenWire.signals[i].signal.name
local count = greenWire.signals[i].count
items[type..","..name] = count
end
end
if redWire then
for i=1, #redWire.signals do
local type = redWire.signals[i].signal.type
local name = redWire.signals[i].signal.name
local count = redWire.signals[i].count
if items[type..","..name] ~= nil then
items[type..","..name] = items[type..","..name] + count
else
items[type..","..name] = count
end
end
end
return items
end