Replace underground belt

Place to get help with not working mods / modding interface.
Post Reply
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Replace underground belt

Post by darkfrei »

So, how to make replacing correctly?

Code: Select all

function replace_underground_belt (old_underground_belt_entity, new_underground_belt_name)
	local data = old_underground_belt_entity
	-- http://lua-api.factorio.com/latest/LuaSurface.html#LuaSurface.create_entity
	surface.create_entity{name=new_underground_belt_name, position=data.position, direction=data.direction, force=data.force, fast_replace=true, 'underground-belt' = data.input_or_output}
	
	-- http://lua-api.factorio.com/latest/LuaEntity.html#LuaEntity.neighbours
	local neighbours = data.neighbours -- When called on an underground transport belt, this is the other end of the underground belt connection, or nil if none.
	data = neighbours[1]
	
	surface.create_entity{name=new_underground_belt_name, position=data.position, direction=data.direction, force=data.force, fast_replace=true, 'underground-belt' = data.input_or_output}
end

Cribbit
Fast Inserter
Fast Inserter
Posts: 199
Joined: Mon Oct 09, 2017 9:35 pm
Contact:

Re: Replace underground belt

Post by Cribbit »

You should probably include some details of what you're trying to do.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Replace underground belt

Post by darkfrei »

Cribbit wrote:You should probably include some details of what you're trying to do.
I want to replace by the script underground belts like it makes the player.

Post Reply

Return to “Modding help”