[15.34] get_trains() doesn't return wagon-only trains
Posted: Wed Sep 13, 2017 3:21 am
This causes inconsistencies in mod state when a map is reloaded or a mod is added to a map, and having to postprocess the results of find_entities_filtered seems crude and redundant and error-prone, since discovering all the variants isn't at all trivial.
To see it,
place a lone cargo wagon, then run
and the train that was just created won't be listed in the get_trains() output. This also happens for all the other ways I've tried that create locomotive-less trains.
Place a locomotive, repeat the dump, remove the locomotive, repeat the dump, mouseover the lone wagon and for a good time call /c game.player.selected.train.speed=4
The train's still there, and you can see it still affects the signalling system, but being sure you've found all no-locomotive trains is, so far as I can tell, not cheap.
(edit: or of course just add the get_trains dump to the on_train_created function . . . )
To see it,
Code: Select all
/c script.on_event(defines.events.on_train_created, function(e) game.print(e.train.id) end)
Code: Select all
/c for _,f in pairs(game.forces) do for _,t in pairs(f.get_trains()) do game.print(t.id) end end
Place a locomotive, repeat the dump, remove the locomotive, repeat the dump, mouseover the lone wagon and for a good time call /c game.player.selected.train.speed=4
The train's still there, and you can see it still affects the signalling system, but being sure you've found all no-locomotive trains is, so far as I can tell, not cheap.
(edit: or of course just add the get_trains dump to the on_train_created function . . . )