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
21 days ago
0.14 - 2.0
272K
Trains Circuit network

b on latest update

24 days 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>

24 days 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>

24 days 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>

24 days ago

Same error here.

24 days ago

Same here. Crashed about 10 seconds after loading save.

24 days ago

Same.

24 days 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

24 days ago

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

24 days ago
(updated 21 days 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?

EDIT: Never mind. I didn't realize this was a runtime error. I only tested loading the mod, not actually using it.

24 days ago

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

24 days 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)

24 days 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).

23 days ago
(updated 23 days 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.

23 days 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. ;-)

23 days 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!

21 days 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).

Ah. I had assumed it was a load-time error, but now I understand it's a run-time error.

21 days ago

will take a look. I have not encountered this bug but it should be easy to track. Expect a quick fix soon.

21 days ago

@hgschmie The fix provided by @kal9001 is working!

21 days ago

This is fixed in 2.5.1.

Thank you for the suggestions; the field should have never been nil so the null-checks are superflous; there was a branch where I forgot to assign the surface field. The prototype (ltn.FreeTrain) was correct but I YOLO'ed the creation and and the type hinting in VSCode did not save me this time.

19 days ago

Thank you! :-) :thumbup:

New response