[1.0.0] script can't connect power-switch to pole with copper wire

Bugs that are actually features.
Post Reply
x2605
Inserter
Inserter
Posts: 41
Joined: Fri Jul 31, 2020 4:08 pm
Contact:

[1.0.0] script can't connect power-switch to pole with copper wire

Post by x2605 »

I think connecting power-switch with electric-pole with copper-wire via scripting is not possible.
Here is some snippet for quick chat command (use it when player is on empty ground with some space)

Code: Select all

/silent-command
local p = game.player local pos = p.surface.find_non_colliding_position( 'rocket-silo', game.player.position, 20, 0.5, true )
if not pos then pos = p.position end
local powerswitch = p.surface.create_entity{name = 'power-switch', force = p.force, position = {pos.x,pos.y}}
local pole1 = p.surface.create_entity{name = 'medium-electric-pole', force = p.force, position = {pos.x-1,pos.y}}
local pole2 = p.surface.create_entity{name = 'medium-electric-pole', force = p.force, position = {pos.x+2,pos.y}}
for _, v in pairs(pole1.neighbours.copper) do if v==pole2 then v.disconnect_neighbour(pole1) break end end
pole1.connect_neighbour{
  wire = defines.wire_type.copper,
  target_entity = powerswitch,
  target_circuit_id = defines.wire_connection_id.power_switch_left
}
Then it will say that "Only red or green cables can be accepted here."
Error is coming from "wire" key in input table of connect_neighbour() method.
I don't know it is right to use target_circuit_id here.
I couldn't find target_wire_id or similar thing in API website.

Code: Select all

powerswitch.connect_neighbour{
  wire = defines.wire_type.copper,
  target_entity = pole1,
  source_wire_id = defines.wire_connection_id.power_switch_left
}
something like this.

Code: Select all

powerswitch.connect_neighbour(pole1)
--or--
pole1.connect_neighbour(powerswitch)
And connect_neighbour(LuaEntity) are also not possible. It seems it is used for connecting between poles.

It throws error,
"Target entity is not electric pole: cannot connect copper wire."


So I couldn't find any scripting way to connect power-switch with electric pole with copper wires.
English is not my native language. Sorry for bad English.
My mods :
Lua API global Variable Viewer (mod portal)
Lua API Event Trace (mod portal)
My tools :
Locale String Editor (github.io webapp)

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2227
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.0.0] script can't connect power-switch to pole with copper wire

Post by boskid »

Unfortunately what you are trying to do is outside of the current specification for the connect_neighbour so its Not a bug. For connecting copper wires right now it can only handle connecting 2 electric poles.

Power switches are kind of special since they have 2 separate places for the wire connections, and they are nothing like electric poles - normal power poles can have up to 5 copper wires connected, while power switches can have at most 1 wire going from each side, but those wires do not add to the wires limit in nearby electric poles.

If you want this to be implemented, please create a proper Modding interface request.

x2605
Inserter
Inserter
Posts: 41
Joined: Fri Jul 31, 2020 4:08 pm
Contact:

Re: [1.0.0] script can't connect power-switch to pole with copper wire

Post by x2605 »

boskid wrote:
Tue Aug 25, 2020 7:32 am
Unfortunately what you are trying to do is outside of the current specification for the connect_neighbour so its Not a bug. For connecting copper wires right now it can only handle connecting 2 electric poles.
https://lua-api.factorio.com/latest/def ... nection_id

If they are not bug, then why these are exist?... I don't see anywhere to use them.
English is not my native language. Sorry for bad English.
My mods :
Lua API global Variable Viewer (mod portal)
Lua API Event Trace (mod portal)
My tools :
Locale String Editor (github.io webapp)

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2227
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.0.0] script can't connect power-switch to pole with copper wire

Post by boskid »

They were introduced somewhere around 0.15.24 when exporting PowerSwitch wires for blueprint string was added.

x2605
Inserter
Inserter
Posts: 41
Joined: Fri Jul 31, 2020 4:08 pm
Contact:

Re: [1.0.0] script can't connect power-switch to pole with copper wire

Post by x2605 »

boskid wrote:
Tue Aug 25, 2020 11:46 am
They were introduced somewhere around 0.15.24 when exporting PowerSwitch wires for blueprint string was added.
Aha, I got it. Thank you for letting me know that.
English is not my native language. Sorry for bad English.
My mods :
Lua API global Variable Viewer (mod portal)
Lua API Event Trace (mod portal)
My tools :
Locale String Editor (github.io webapp)

Post Reply

Return to “Not a bug”