Page 1 of 1

Reading "Trains in block" from a rail entity

Posted: Sat Dec 29, 2018 1:11 am
by Pendarin
The vanilla GUI shows "Trains in block" when you hover over a rail entity. I am in need of exactly that programmatically. I can't seem to find any way to do this. My goal is to determine whether it is safe to place a carriage on a given rail. Not just whether I can (the normal LuaSurface:can_place_entity() does this), but whether it is safe to do.

Thanks!

Re: Reading "Trains in block" from a rail entity

Posted: Wed Jan 09, 2019 7:57 pm
by Rseding91
I'll see if that value is safe to expose to the Lua API.

Re: Reading "Trains in block" from a rail entity

Posted: Wed Jan 16, 2019 3:43 pm
by Pendarin
That would be excellent. As you can imagine, calculating this in Lua is expensive and complicated since Lua isn't exposed at all to the rail block constructs the engine uses. So, in Lua I'd have to model the entire thing by scanning rails, finding nearby signals, checking for branches and loops, etc. Just having the trains in block value available removes the need for all of that in Lua.