Page 1 of 1

Lua. Connect rail-signal to rail

Posted: Thu Oct 20, 2022 12:29 am
by DedMorozzz
Hi all, i'm trying to add rail-signals and rail-chain-signal to created rails, but i do not understand how to join them between each other..

Code: Select all

railEntity = surface.create_entity{ force=game.player.force, name = "straight-rail", position = fPos, direction = defines.direction.west}

sPos = shallowcopy(fPos)
sPos.x = sPos.x+1
sPos.y = sPos.y-2

railSignalEntity = surface.create_entity{ force=game.player.force, name = "rail-signal", position = sPos, direction = defines.direction.west}
sPos.y = sPos.y+3
surface.create_entity{ force=game.player.force, name = "rail-chain-signal", position = sPos, direction = defines.direction.east}
all works, i have a rail, and both signals, but signals are not connected to rail. How do join them?

Re: Lua. Connect rail-signal to rail

Posted: Thu Oct 20, 2022 4:12 am
by boskid
Signals will automatically try to connect to rails when they are created. Only things you need to take care of is for the position to be exactly on a tile center, direction to be correct and to not have signals on an adjacent tile in the direction of a signal.

Your signals have incorrect direction.

Re: Lua. Connect rail-signal to rail

Posted: Thu Oct 20, 2022 4:18 am
by DedMorozzz
boskid wrote: Thu Oct 20, 2022 4:12 am Your signals have incorrect direction.
Oh! You are right. Thank you, now it works