Page 1 of 1

connect_neighbour and disconnect_neighbour for Power Switch

Posted: Wed Mar 08, 2017 6:49 pm
by Yoyobuae
Simple enough. Make this two API methods work for power switches:
http://lua-api.factorio.com/latest/LuaE ... _neighbour
http://lua-api.factorio.com/latest/LuaE ... _neighbour

This would enable creating a mod for auto connecting power switches to power poles, which is an often requested feature (specially in relation to blueprinting).

Basically the API should allow specifying copper wire to be used when connecting a power switch entity with a power pole (or the other way around). The source_circuit_id (or target_circuit_id) parameter could naturally refer to the left/right sides of the power switch.

Re: connect_neighbour and disconnect_neighbour for Power Switch

Posted: Sat Sep 05, 2020 7:52 pm
by PFQNiet
You know when you search something on Google and find someone else with the same idea as you from years ago?

This is one of those moments. Is this possible? I'd love to have this feature.

Readily anticipated issue: you have to specify which side of the Power Switch to connect to. This could probably be done just by allowing defines.wire_type.copper but only if connecting (power pole, power pole) or (power pole, power switch).

I know Power Switches don't get much love but there's so much potential here!

Re: connect_neighbour and disconnect_neighbour for Power Switch

Posted: Thu Oct 29, 2020 10:55 pm
by Rseding91
Added for 1.1.

Re: connect_neighbour and disconnect_neighbour for Power Switch

Posted: Wed Aug 31, 2022 11:18 am
by Natha
I have a question related to this topic.

How can you read the copper connections of a power switch? When using "circuit_connection_definitions", it gives you all connected poles but not which side of the switch (just -1 for source_circuit_id and target_circuit_id).

Re: connect_neighbour and disconnect_neighbour for Power Switch

Posted: Wed Aug 31, 2022 1:16 pm
by boskid
API for power switches in 1.1.x is quite limited, i see no clean way of finding which side of a power switch is connected to an electric pole. Only usable information here is that if a power switch is connected to 2 electric poles, the LuaEntity::neighbours in the "copper" output will return 2 electric poles: [1] is for left and [2] is for right connection. If there is only one pole connected it will take an index [1] in the copper table in which case it may not be possible to resolve side directly. This will be easy to do in 1.2.x.