Subsurface - build your base underground!

by Natha

While everyone is looking up to space, other planets and the rest of the universe, there is a whole world buried directly underneath us. Use this opportunity to declutter your factory logistics by routing it under your base and explore the underground!

Content
14 days ago
1.1 - 2.1
8.41K
Transportation Logistics Trains Environment Mining

b Crash when trying to build subway (fix included)

2 days ago

When trying to build a subway element going up, the game crashes with this error:

The mod Subsurface - build beneath your base! (1.1.28) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event Subsurface::on_built_entity (ID 6)
__Subsurface__/scripts/trains.lua:10: attempt to index local 'rail' (a nil value)
stack traceback:
    __Subsurface__/scripts/trains.lua:10: in function 'subway_built'
    __Subsurface__/control.lua:630: in function <__Subsurface__/control.lua:560>

The cause seems to be that i copy-pasted the segment (from a different level). This makes the rails leftover "subway rails" rather than normal rails. Placing the subway on top of these seems to be what causes the crash - if I remove the 5 tracks underneath where I'm placing, it works.

AI diagnosis and fix (connected with Factorio MCP so grounded in my actual game):

The existing subway-rail entities face north. subway_built() first tries to create new rails, then falls back to finding existing ones with exactly the tunnel’s direction. For a south-facing tunnel, creation fails because the rails already exist, and the fallback misses them because their direction is north. Line 10 then dereferences nil.

Fix: accept existing rails with the same alignment in either direction (north/south or east/west). Also handle failure explicitly: if no compatible rail can be created or found, cancel placement cleanly instead of accessing rail.

2 days ago

line 10 refers to scripts/trains.lua

New response