LTN - Logistic Train Network

by Optera

Adds logistic-train-stops acting as anchor points for building a fully automated, train logistic network. It can handle all possible train configuration. Just send all trains to depots and LTN will pick the best suitable train for a job. LTN cuts the amount of rolling stock required to run a megabase down to 30% or less. With cargo ships installed also adds a logistic port for ships.

Content
a day ago
0.14 - 2.0
271K
Trains Circuit network

b on latest update

a day ago

Notice

The mod LTN - Logistic Train Network (2.5.0) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event LogisticTrainNetwork::on_nth_tick(2)
LogisticTrainNetwork/script/dispatcher.lua:428: attempt to index field 'surface' (a nil value)

stack traceback:
LogisticTrainNetwork/script/dispatcher.lua:428: in function <LogisticTrainNetwork/script/dispatcher.lua:426>
[C]: in function 'sort'
LogisticTrainNetwork/script/dispatcher.lua:426: in function 'getFreeTrains'
LogisticTrainNetwork/script/dispatcher.lua:647: in function 'ProcessRequest'
LogisticTrainNetwork/script/dispatcher.lua:14: in function <LogisticTrainNetwork/script/dispatcher.lua:25>

a day ago

The same...

Error while running event LogisticTrainNetwork::on_nth_tick(2)
LogisticTrainNetwork/script/dispatcher.lua:428: attempt to index field 'surface' (a nil value)
stack traceback:
LogisticTrainNetwork/script/dispatcher.lua:428: in function <LogisticTrainNetwork/script/dispatcher.lua:426>
[C]: in function 'sort'
LogisticTrainNetwork/script/dispatcher.lua:426: in function 'getFreeTrains'
LogisticTrainNetwork/script/dispatcher.lua:647: in function 'ProcessRequest'
LogisticTrainNetwork/script/dispatcher.lua:141: in function <LogisticTrainNetwork/script/dispatcher.lua:25>

a day ago

same
The mod LTN - Logistic Train Network (2.5.0) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event LogisticTrainNetwork::on_nth_tick(2)
LogisticTrainNetwork/script/dispatcher.lua:428: attempt to index field 'surface' (a nil value)
stack traceback:
LogisticTrainNetwork/script/dispatcher.lua:428: in function <LogisticTrainNetwork/script/dispatcher.lua:426>
[C]: in function 'sort'
LogisticTrainNetwork/script/dispatcher.lua:426: in function 'getFreeTrains'
LogisticTrainNetwork/script/dispatcher.lua:647: in function 'ProcessRequest'
LogisticTrainNetwork/script/dispatcher.lua:141: in function <LogisticTrainNetwork/script/dispatcher.lua:25>

a day ago

Same error here.

a day ago

Same here. Crashed about 10 seconds after loading save.

a day ago

Same.

a day ago

had the same issue went back to 2.4.3 fixed it for me
how to replace if you don't know
Delete LogisticTrainNetwork_2.5.0.zip from your mods folder in %appdata%\Roaming\Factorio\mods
Put LogisticTrainNetwork_2.4.3.zip in that folder

a day ago

Lets all hope that we get a hotfix by tommorow to this massive issue.

a day ago

I just tested this and did not trigger any error. However, that was on a brand new save. (Also, I don't have Space Age DLC.)

Are you guys getting this error with new saves, or when trying to open an already existing save? Or is this happening when you just try to start the game?

a day ago

did some digging: dispatcher.lua: 390 table insert without surface missing line 392:
surface = trainData.surface,

a day ago

had the same issue went back to 2.4.3 fixed it for me
how to replace if you don't know
Delete LogisticTrainNetwork_2.5.0.zip from your mods folder in %appdata%\Roaming\Factorio\mods
Put LogisticTrainNetwork_2.4.3.zip in that folder

I just selected the previous release via the pull down menu on the mod screen (Factorio 2.0)

a day ago

Getting the same error. Happens the moment a requester station sends out a new request. Happening in an existing save (and on an existing station that used to work in the previous version).

13 hours ago
(updated 13 hours ago)

Same for me :(
Going back to 2.4.3

271.726 Error MainLoop.cpp:1468: Exception at tick 92234254: The mod LTN - Logistic Train Network (2.5.0) caused a non-recoverable error.
Please report this error to the mod author.
Error while running event LogisticTrainNetwork::on_nth_tick(2)
LogisticTrainNetwork/script/dispatcher.lua:428: attempt to index field 'surface' (a nil value)
stack traceback:
LogisticTrainNetwork/script/dispatcher.lua:428: in function <LogisticTrainNetwork/script/dispatcher.lua:426>
[C]: in function 'sort'
LogisticTrainNetwork/script/dispatcher.lua:426: in function 'getFreeTrains'
LogisticTrainNetwork/script/dispatcher.lua:647: in function 'ProcessRequest'
LogisticTrainNetwork/script/dispatcher.lua:141: in function <LogisticTrainNetwork/script/dispatcher.lua:25>
271.726 Error ServerMultiplayerManager.cpp:84: MultiplayerManager failed: "The mod LTN - Logistic Train Network (2.5.0) caused a non-recoverable error.
Please report this error to the mod author.
Error while running event LogisticTrainNetwork::on_nth_tick(2)
LogisticTrainNetwork/script/dispatcher.lua:428: attempt to index field 'surface' (a nil value)
stack traceback:
LogisticTrainNetwork/script/dispatcher.lua:428: in function <LogisticTrainNetwork/script/dispatcher.lua:426>
[C]: in function 'sort'
LogisticTrainNetwork/script/dispatcher.lua:426: in function 'getFreeTrains'
LogisticTrainNetwork/script/dispatcher.lua:647: in function 'ProcessRequest'
LogisticTrainNetwork/script/dispatcher.lua:141: in function <LogisticTrainNetwork/script/dispatcher.lua:25>"
271.726 Info ServerMultiplayerManager.cpp:808: updateTick(92234254) changing state from(InGame) to(Failed)
271.726 Quitting: multiplayer error.

11 hours ago
-- sort best matching train to top
table.sort(filtered_trains, function(a, b)
    -- fix 2.5.0: attempt to index field 'surface' (a nil value)
    if a.surface == nil or b.surface == nil then
        return false
    -- if A is on the same surface as the stop and B is not, return true
    elseif a.surface.index == stop_surface_index and b.surface.index ~= stop_surface_index then
        return true
        -- if B is on the same surface as the stop and A is not, return false
    elseif b.surface.index == stop_surface_index and a.surface.index ~= stop_surface_index then
        return false
        -- else do normal checks (either both stops are on the same or on a different surface)
    elseif a.depot_priority ~= b.depot_priority then
        --sort by priority
        return a.depot_priority > b.depot_priority
    elseif a.inventory_size ~= b.inventory_size and a.inventory_size >= size then
        --sort inventories capable of whole deliveries
        -- return not(b.inventory_size => size and a.inventory_size > b.inventory_size)
        return b.inventory_size < size or a.inventory_size < b.inventory_size
    elseif a.inventory_size ~= b.inventory_size and a.inventory_size < size then
        --sort inventories for partial deliveries
        -- return not(b.inventory_size >= size or b.inventory_size > a.inventory_size)
        return b.inventory_size < size and b.inventory_size < a.inventory_size
    else
        -- if one stop is on the same surface and the other is not, return
        if not a.provider_distance then return false end
        if a.provider_distance and not b.provider_distance then return true end

        return a.provider_distance < b.provider_distance
    end

Just a polite suggestion for speeding up the fix. ;-)

an hour ago

did some digging: dispatcher.lua: 390 table insert without surface missing line 392:
surface = trainData.surface,

Manually adding this line to mimic the insert call just below directly fixed the issue for me. Super helpful!

New response