Page 1 of 1

Replace underground belt

Posted: Mon Oct 23, 2017 6:00 pm
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

Re: Replace underground belt

Posted: Mon Oct 23, 2017 6:05 pm
by Cribbit
You should probably include some details of what you're trying to do.

Re: Replace underground belt

Posted: Mon Oct 23, 2017 6:25 pm
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.