Page 1 of 1

Help Automating Circuit Network Creation

Posted: Tue Aug 31, 2021 2:18 am
by francoisdevlin
Hi, I'm trying to programmatically create a circuit network for a combinator based mod I'm working on. I've found the connect_neighbour method here:

https://lua-api.factorio.com/latest/Lua ... _neighbour

However, it requires providing a circuit network id, and I need to create a new one. Is there a method to create circuit networks? I couldn't find one here:

https://lua-api.factorio.com/latest/Lua ... twork.html

Thanks

Re: Help Automating Circuit Network Creation

Posted: Tue Aug 31, 2021 7:37 am
by DaveMcW
It does not need a "circuit network id", it needs a circuit connector id.

Code: Select all

/c
a = game.player.surface.create_entity{name = "arithmetic-combinator", force = game.player.force, position = {-0.5, 0}}
d = game.player.surface.create_entity{name = "decider-combinator", force = game.player.force, position = {0.5, 0}}
a.connect_neighbour{
  target_entity = d,
  wire = defines.wire_type.red,
  source_circuit_id = defines.circuit_connector_id.combinator_output,
  target_circuit_id = defines.circuit_connector_id.combinator_input,
}

Re: Help Automating Circuit Network Creation

Posted: Tue Aug 31, 2021 11:08 am
by francoisdevlin
Interesting, I tried something similar to that and it didn't work for me, I got an error message in game. Maybe I fat fingered something. I did find a way to make it work, here's what I did:

Code: Select all

function new_network_id(entity)
        local lamp1 = entity.surface.create_entity{
                name = 'small-lamp',
                position = entity.position,
                direction = entity.direction,
                force = entity.force,
        }
        local lamp2 = entity.surface.create_entity{
                name = 'small-lamp',
                position = entity.position,
                direction = entity.direction,
                force = entity.force,
        }
        lamp1.connect_neighbour({
                wire=defines.wire_type.red,
                target_entity=lamp2
        })
        local n = lamp1.get_circuit_network(defines.wire_type.red, defines.circuit_connector_id.lamp)
        local return_value = n.network_id + 0;
        lamp1.destroy()
        lamp2.destroy()
        return return_value
end
I ended up wiring things like this

Code: Select all

a = game.player.surface.create_entity{name = "arithmetic-combinator", force = game.player.force, position = {-0.5, 0}}
d = game.player.surface.create_entity{name = "decider-combinator", force = game.player.force, position = {0.5, 0}}
network_id = new_network_id(a)

a.connect_neighbour{
  target_entity = d,
  wire = defines.wire_type.red,
  source_circuit_id=network_id,
  target_circuit_id=network_id,
  source_wire_id = defines.circuit_connector_id.combinator_output,
  target_wire_id = defines.circuit_connector_id.combinator_input,
}
I think I'll try your solution though, I like it better.