Connecting entities by copper wire but not autoconnect to power poles

Place to get help with not working mods / modding interface.
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Connecting entities by copper wire but not autoconnect to power poles

Post by mrvn »

I was wondering if I can make entities that can be connected by copper wire in some way that the LUA script can trace. Given one entity I need to find connected entities. And because I don't want to end up getting all power poles I don't want any automatic copper wire connections being made.

Note: The visible entity already has a train-stop, a hidden constant combinator, a visible constant combinator, a lamp and a wooden chest. So I'm not afraid to add some more to make it work best.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1742
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by Pi-C »

mrvn wrote: Tue Nov 02, 2021 11:59 pm I was wondering if I can make entities that can be connected by copper wire in some way that the LUA script can trace. Given one entity I need to find connected entities. And because I don't want to end up getting all power poles I don't want any automatic copper wire connections being made.
Not sure I've understood that correctly, but couldn't you make a new electric-pole prototype and filter for that prototype's name? You can then check LuaEntity.neighbours and remove unwanted connections.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by mrvn »

If I place two entities on each side of the base and they automatically connect to existing power poles with a copper wire then there is a near unity chance they end up being connected by copper wire. That must not happen. I only want connections placed manually by the player or by blueprints.

If I have to I can use red/green wires but those are useful for carrying signals. Using one wire to connect my entities would a) transmit signals from one entity to the other and b) only leave one other color to read/send signals. So I'm hoping to use the copper wire as a neutral wire.
Xorimuth
Filter Inserter
Filter Inserter
Posts: 708
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by Xorimuth »

My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
meifray
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Sat May 29, 2021 6:12 pm
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by meifray »

mrvn wrote: Fri Nov 05, 2021 3:01 pm If I place two entities on each side of the base and they automatically connect to existing power poles with a copper wire then there is a near unity chance they end up being connected by copper wire. That must not happen. I only want connections placed manually by the player or by blueprints.

If I have to I can use red/green wires but those are useful for carrying signals. Using one wire to connect my entities would a) transmit signals from one entity to the other and b) only leave one other color to read/send signals. So I'm hoping to use the copper wire as a neutral wire.
I think it means you will need some thing like this

Code: Select all

local fucntion on_pole_built(in_pole_entity)
	local lname="lonely-power-pole";
	if in_pole_entity.name==lname then
		in_pole_entity.disconnect_neighbour(defines.wire_type.copper);
	else
		for _,e in pairs(in_pole_entity.neighbours["copper"])
			if(e.name==lname) then
				e.disconnect_neighbour{wire=defines.wire_type.copper,entity=in_pole_entity};
			end
		end
	end
	return;
end
but currently I dont really know how blueprint and ghost like,so it might be fundamentally wrong.
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by mrvn »

That won't work if the blueprint has a copper wire going from lonely-power-pole to power-pole to other lonely-power-pole.

But maybe I could avoid that middle pole by providing a tool to connect 2 lonely-power-pole with a copper wire regardless of their distance. I could then set the wire reach of lonely-power-pole to 0 so it doesn't connect with anything automatically.

Can I make a tool to select lonely-power-pole for connection?

Update: Just tried that idea. Power poles with wire reach 0 will keep their wires when you load the game but when you place a blueprint the wire disappears. So at a minimum I have to store the wire connections in the blueprint as tags and then recreate the wires when the blueprint gets placed.

I guess now I have to learn about making a tool.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1742
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by Pi-C »

mrvn wrote: Fri Nov 05, 2021 6:37 pm But maybe I could avoid that middle pole by providing a tool to connect 2 lonely-power-pole with a copper wire regardless of their distance. I could then set the wire reach of lonely-power-pole to 0 so it doesn't connect with anything automatically.
Do you place the two lonely-power-poles per script? In this case, you should be able to connect them per script even if they are farther away than the prototype's wire reach allows. Obviously, that won't work if the poles are placed by players.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by mrvn »

Pi-C wrote: Fri Nov 05, 2021 6:52 pm
mrvn wrote: Fri Nov 05, 2021 6:37 pm But maybe I could avoid that middle pole by providing a tool to connect 2 lonely-power-pole with a copper wire regardless of their distance. I could then set the wire reach of lonely-power-pole to 0 so it doesn't connect with anything automatically.
Do you place the two lonely-power-poles per script? In this case, you should be able to connect them per script even if they are farther away than the prototype's wire reach allows. Obviously, that won't work if the poles are placed by players.
Initially the poles would be placed by script when the main entity is build. On blueprints the idea was that the pole would be included to preserve the wire connections. So the ghosts of poles would be build by blueprint and revived when the main entity is build.

The wire disappears when I place the blueprint. I have yet to test if I can connect 2 ghosts with wires and have the wire appear when the poles get revived.

Update: ghost_pole.connect_neighbour(other_ghost_pole) returns false and no wire appears. At least outside the wire reach. How do I connect 2 entities past their wire reach?
meifray
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Sat May 29, 2021 6:12 pm
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by meifray »

so there`s 2 thing

1.disconnected the lonely power pole when built
2.keep connection in blueprint


so I think it can be something like this

Code: Select all


func on_built(inentity)
{
	func handle_pole(ine)
	{
		if(is_registered(ine))
			recover_state(ine);
		else
			ine.disconnect();
	};
	
	
	if(inentity==ghost and inentity.ghost_name==lonely-power-pole)
	{
		register_state(inentity);
		return;
	}
	if(inentity==lonely-power-pole)
	{
		handle_pole(inentity);
		return;
	}
	for _,e in pairs(inentity.connected)
		if(e==lonely-power-pole)
			handle_pole(e);
	return;
}

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3724
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by DaveMcW »

mrvn wrote: Fri Nov 05, 2021 7:26 pmHow do I connect 2 entities past their wire reach?
Build them close together, connect them, then teleport them to their final position.
meifray
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Sat May 29, 2021 6:12 pm
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by meifray »

DaveMcW wrote: Sat Nov 06, 2021 8:37 am
mrvn wrote: Fri Nov 05, 2021 7:26 pmHow do I connect 2 entities past their wire reach?
Build them close together, connect them, then teleport them to their final position.
but isnt teleport only work on character and car?
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3724
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by DaveMcW »

Read the teleport documentation more carefully.
meifray
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Sat May 29, 2021 6:12 pm
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by meifray »

DaveMcW wrote: Sat Nov 06, 2021 8:42 am Read the teleport documentation more carefully.
is there a full list? or I should test it and maintain it in wiki ?
Pi-C
Smart Inserter
Smart Inserter
Posts: 1742
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by Pi-C »

mrvn wrote: Fri Nov 05, 2021 7:26 pm Update: ghost_pole.connect_neighbour(other_ghost_pole) returns false and no wire appears. At least outside the wire reach. How do I connect 2 entities past their wire reach?
Sorry, my mistake. The thing I (wrongly) remembered was from a problem I had with Picker dollies: When one of my base entities was moved, I had to move (teleport) its other entities as well. One of these was a power pole, and when I moved a connected pole, the wire could be stretched beyond max_wire_distance, so I had to cut the connection. I just tested: You can't make a connection for distances exceeding max_wire_distance. But creating both entities within reach of each other and then teleporting them to their final positions would work.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Connecting entities by copper wire but not autoconnect to power poles

Post by mrvn »

The goal of it is to make it easy for the user to connect the entities and to preserve the connection in blueprints. This fails at both of those goals.

If I have to do all the connecting and connections in LUA and working around the game then I can just use LuaRendering.draw_line instead of wires.
Post Reply

Return to “Modding help”