get_connected_rail oscillates (bad title)

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

get_connected_rail oscillates (bad title)

Post by d3x0r »

I have a train on a track, from the first front mover... I would *think* that if have a bit of track that I should be able to use rail.get_connected_entity{ {rail_direction=defines.rail_direction.back, rail_connection_direction=defines.rail_connection_direction.straight} ) to go through and get a linear line of track; this is not what happens, and instead it oscillates between two peices of track doing it this way....

but apparently on curves, going around a circle... I have to do direction.left or direction.right depending on the direction I'm iterating.
But worse, if I just go rail_direction.back, it will oscillate between two bits of track instead of going to the next one.
(Yes, I can store the prior track, and if the next is the same as the one I just came from, I can go the other way instead).

I added a flying-text every second at the position of each of the rails (although I do add count/2 to the x position because the first iteration was overlapping)

(1) is always white as the starting point
I color coded the other directions

red is .back, .straight
cyan is .forward, .left
blue is .back, .right
purple is .forward, .straight

(green would be backward, .left )
(yellow would be forward .right)

This first image, the train is ... in position 1. The next image, the train is moved forward a little so it's front_rail is the next rail ahead.

So; this shows me 1) .forward and .backward not not relative to the front-mover direction of the train I'm in...
and 2) forward and backward are not even a linear list.
For the purposes of this train mod, it doesn't matter a lot which direction I go, because the energy will be re-filled on the next tick anyway in either direction (except in low power conditions)...
circle1.jpg
circle1.jpg (46.25 KiB) Viewed 847 times
circle2.jpg
circle2.jpg (52.06 KiB) Viewed 847 times
so; the real 'request' would be...
someday I'd like to get the rails that are underneath the train, preferably in a list from first_rail to last_rail.
Or; more complex; I'd like to have something like a rail-network identifier and associated entities to that network that I could just access a power source attached somewhere along the rail; assuming there's still a path to it. (Although RailPowerSystem does also transport red/green signals and power with the rails; and they would still need something to connect to). So in this case there is a Rail_Accumulator that has kJ storage big enough for one tick of the train to run, and each rail segment has (although corners, since they are longer, should have 2) so basically the rail that each engine is one is the accumulator it should use. (again if it's on a curve, it could be 2-3 engines on the curve) it's not such a big deal for horizontal stretches.
Post Reply

Return to “Modding interface requests”