[MOD 0.15] SmartTrains 2.0.5

Topics and discussion about specific mods
Post Reply
StoneLegion
Filter Inserter
Filter Inserter
Posts: 668
Joined: Fri Sep 05, 2014 7:34 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by StoneLegion »

Yeah I think the above is more what happen.

So I had L-CC-L.

I sadly for a while had the lack of coal in my system so sometimes it did not meat the 25 or 50min I forgot what I had set. So it goes to the next station and say... Dam this guy is an idiot so lets keep it on the list. Though it seems once it's on the list twice in a row then it stays on it for good no matter if it gets fuel the 2nd time.

I could be wrong it's not really a bug or an issue I will just make sure I don't derp next time.

Corman
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Sep 24, 2015 2:18 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by Corman »

I'm having trouble applying circuits to 2 headed trains.

I have a train with 2 engines named Ghakk and Kody on opposite ends. Smart trains uses Ghakk as the name for the train. If Ghakk stops at the station it works fine. If Kody stops at the station it will not accept the circuit conditions of the the station. So it seems that the engine at the station must match the train name in order to accept the circuit. Is there a work around for this? Or do i need to stop using 2 headed trains?

waduk
Filter Inserter
Filter Inserter
Posts: 372
Joined: Tue Feb 10, 2015 5:44 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by waduk »

Corman wrote:I'm having trouble applying circuits to 2 headed trains.

I have a train with 2 engines named Ghakk and Kody on opposite ends. Smart trains uses Ghakk as the name for the train. If Ghakk stops at the station it works fine. If Kody stops at the station it will not accept the circuit conditions of the the station. So it seems that the engine at the station must match the train name in order to accept the circuit. Is there a work around for this? Or do i need to stop using 2 headed trains?
Sorry, i will chip in, not much of a help because i never use two head train. But have you take a look the sample save file (1st post) that Choumiko posted ? He use two head train, and it works flawlessly.
See how Choumiko setup that.

Corman
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Sep 24, 2015 2:18 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by Corman »

Thanks. I checked the save and found he had Go to station set. When i set station 2 with a go to to 1 it started to work. Bug or required setting I don't know. But it works now.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by Choumiko »

Corman wrote:Thanks. I checked the save and found he had Go to station set. When i set station 2 with a go to to 1 it started to work. Bug or required setting I don't know. But it works now.
Can you show a screenshot of the lines rules of when it worked and when it didn't? I'm using lines with 2 headed trains that have mixed settings (some only wait for signal, some let the signal decide to which station to go) and so far it works

BlaatMekker
Inserter
Inserter
Posts: 29
Joined: Sun Dec 28, 2014 10:01 am
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by BlaatMekker »

I just loaded an old save and I keep getting these errors when doing anything with trains:
Error in SmartTrains:
__SmartTrains__/control.lu:667: Error while running the event handler: __SmartTrains__/gui.lua:313: attempt to index field settings' (a nil value)
Using ST 0.3.68 with Factorio 0.12.10.

While in-game it appears that I'm missing a button to remove old train lines.

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

Is there a way to get a train to return to the first station in the line when empty?

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by Choumiko »

BlaatMekker wrote:I just loaded an old save and I keep getting these errors when doing anything with trains:
Error in SmartTrains:
__SmartTrains__/control.lu:667: Error while running the event handler: __SmartTrains__/gui.lua:313: attempt to index field settings' (a nil value)
Using ST 0.3.68 with Factorio 0.12.10.

While in-game it appears that I'm missing a button to remove old train lines.
You could use /c remote.call("st", "hardReset", true) to delete all SmartTrain related data, this will get rid of the error. Downside is that you'll loose all your Trainlines etc. Or if you still have a save without errors give it to me and i'll see where my upgrading/migration code fails (assuming the save had an older version of SmartTrains).
The Lone Wolfling wrote:Is there a way to get a train to return to the first station in the line when empty?
Yes there is. Use smart trainstops, some combinators and a trainline with "leave when signal" and Goto station # set to 1.
The smart trainstop outputs 3 special signals if a train is there, so you'll have to eliminate them from the signal and then check with a decider for everything = 0 and output some signal to the lamp at the trainstop.
I can post a bleuprint string if you need one (or i could update the demo with some stuff i have build recently)

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

A blueprint string would be helpful.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by Choumiko »

Image

The smart train stop isn't included in the blueprint, since it doesn't really work when placed by robots. Just connect it up like the lamp and constant combinator (they can be removed) in the blueprint.

Image
Trainline with rules set. This will make trains wait at Item Load until they are full. At Item Unload/Unload 2/Unload 3 they will wait for 30 seconds or when they are empty before they will go to Item Load, skipping stations. When they are not emptied within 30 seconds they'll go to the next station. Since you obviously have a use for that, let me know what you think about this: https://github.com/Choumiko/SmartTrains/issues/6
Right now i'm leaning towards not a bug as it seems usefull.
String
PS: The blueprint will have the lamp be on even if there's no train at the station. This can be prevented by an additional combinator but i think it doesn't matter, since it works without.

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

Thanks! I think I get the idea now.

And yes, I would consider that in the category of "useful bugs". (In other words, it's probably unintended behavior, but it's useful unintended behavior.)

Also: I don't suppose you could add a feature to read / set filters? It'd be handy to be able to set the filters to trains set to a line automatically. (Also: I wish there was a quick way to say "set the entire wagon to only hold <X>")

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by Choumiko »

The Lone Wolfling wrote:Thanks! I think I get the idea now.

And yes, I would consider that in the category of "useful bugs". (In other words, it's probably unintended behavior, but it's useful unintended behavior.)
Yeah, let's say it's working as intended :lol: I can't remember what i wanted when i added that in.
The Lone Wolfling wrote:Also: I don't suppose you could add a feature to read / set filters? It'd be handy to be able to set the filters to trains set to a line automatically. (Also: I wish there was a quick way to say "set the entire wagon to only hold <X>")
Sounds reasonable, i'll add it to my ever growing todo list, might be a while

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

After fiddling around with SmartTrains for a while, I have come to the conclusion that it does something different than what I'm looking for. I'm looking for something that'll give trains logistic-bot like behavior, and this doesn't. You can make it simulate certain aspects, but only in a very "square peg in round hole" sort of way.

What I'd like to do is to treat trains as though they were logistic robots - so you mark stations as though they were part of a logistic network (i.e. "keep 100 of <x> in stock", or "this station provides <y>" or "please take all <x> away from this station") and have everything "just work". Some specifics:
  • Partial requests should be distributed semi-evenly. So if I have 3 stations requesting copper plates, I shouldn't end up with 1 getting all loads of copper plates and the others getting nothing. This is one of the big frustrations I'm having with this mod - you can't really do this.
  • I should be able to designate stations as idle stations, where trains will go if there's nothing for them to do.
  • It should set filter slots (so, for instance, if I have a station that produces both lead plates and sulfuric acid barrels, and something requests lead plates, it won't grab sulfuric acid unless there's somewhere it should go to too).
  • Trains should pick up either a whole load or whatever is in the station, whichever is less.
  • Trains should fill up on fuel semi-intelligently. (So if they are heading past an empty fuel station and they aren't full, stop and refuel)
  • Trains should not go to idle stations unless there is nothing for them to do and they are full on fuel.
  • Ideally, trains should be smart enough to move to the next station if they are blocking enough trains.
  • Ideally, trains should be smart enough to not all try to go to the same station at once unless it's really necessary.
  • It should coalesce requests. So for instance, if there's something that requests sulfuric acid on the way, it should pick up both and deliver both.
I am aware that this requires solving the TSP in general. But an approximation should work. Even just "find the nearest (as in fastest to get to) station that can fulfill a request and head there, load up, and head to the station that least recently requested that item (and that doesn't have a train on the way)" should work reasonably well.

So, with that in mind: is what I'm trying to do outside of the design goals of this mod? Or is it a limitation of the current state of the mod? Because currently this isn't really feasible.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by Choumiko »

The Lone Wolfling wrote:So, with that in mind: is what I'm trying to do outside of the design goals of this mod? Or is it a limitation of the current state of the mod? Because currently this isn't really feasible.
Completely outside of the goals, sorry (because that's a pretty list with interesting ideas).
A lot of your ideas would require calculating/having access to the actual layout of your rail network (travel distances between stations) and/or manipulating train pathfinding (probably by constantly renaming train stations). API access isn't possible, that would leave calculating, which is probably beyond my abilities (at least in a way that doesn't lag your game to death ;) )

Manipulating path finding has the issue that a train completely stops when recalculating it's path. I don't know how it behaves when multiple train stations get renamed in the same tick, my guess is that the effects would not be good, e.g. trains stopping every time a station get's renamed to recalculate and other things.

The one thing SmartTrains sort of does from your list is
  • Trains should fill up on fuel semi-intelligently. (So if they are heading past an empty fuel station and they aren't full, stop and refuel)
They don't refuel when going past a station, but add a refueling station to the end of their schedule when they are under a certain fuelvalue. So if you set up your schedules in a way that the refueling station is near the last station in your schedule (and in the way to the first station) it's nearly the same. I have refueling stations at the exit of my base trainyard(s), one for each main branch.

You can do some pretty/fun stuff when using train lines and combinators together:
Smart Oil
The above uses smart trainstops with the Goto station # signal value to make trains skip stations when they are full and/or leave a station when the tanks are near empty/not filling up quick enough. E.g. a train at Oil 7 arrives directly after another one leaves so the tanks are only filled by 100 oil, once they are < 10 it immediately goes to Oil 4 (where the train before it never went because it got filled at Oil 7), where it get's filled to the max. Once it detects that it's full it skips all other stations and goes directly to unloading. In my case that saves me from having to setup trains for different stations/schedules as well as quite some travel time (~ 3minutes from Oil 7 to Oil 6 wiht 0 second stops at each station between).
One could do something similar for ore trains or even a supply train that only goes to stations when they are signaling that they need to be resupplied.

The better one is with combinators the more SmartTrains could do, though i doubt that any of your ideas would be doable. Partial requests/evenly distributing could be possible in the form of "if item at station < Y then unload X items, go to the next station, if empty or train cargo < Z go to loading station else go to the next station.

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

Limited mod APIs strike again. (I really wish that games would either have a mod API that allowed full access to the game engine (KSP, for instance, at least after the file restrictions were removed), or left it entirely to unofficial versions that did (DF). But this Frankenstein "sure we have a mod API! What? You want to do that? Wait somewhere between a week to never..." is really rather frustrating, to the point where I've thought of starting a DFHack-like project for Factorio (Or rather, just a plugin/hack that allowed memory peek / poke from Lua, from which you can build everything else).) It's the difference between handing someone a bunch of lego blocks and handing someone a bunch of lego blocks half of which are glued together in the way they were "obviously supposed to be used". (And what many people forget is that it's not just that the current API doesn't have the tools, it's that it kills fast turnaround for development. In Minecraft, if I want to try something random and off-the-wall I can hack it together quickly, see if it makes some vague sort of sense, and if it does I can come back later and tidy things up. In Factorio... Not so much. Step one is tidy it up to the point where it can go into a request (at which point it's entirely likely that it'll be shot down as "why on Earth would you do that off-the-wall thing"), step two is wait a week to infinity.)

But I digress. It's too bad to hear that SmartTrains doesn't do what I want, and even more to hear that it essentially cannot be done currently. Consider me enlightened as to the state of mod development for Factorio.

Back on topic:

Two things that would make my life substantially easier (that *are* probably possible), are a) a signal that signals when a train is stopped at it (or a track segment that signals when there is a train on it, either works), and b) a way to distinguish between items in different cars in the train. (So, for instance, distinguishing between "this train has crude oil in the second car" versus "this train has crude oil in the first car")

MrDrummer
Fast Inserter
Fast Inserter
Posts: 131
Joined: Sat Nov 22, 2014 2:51 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by MrDrummer »

Man, when I first installed this mod, I didn't know how to use combinators. Now after watching a few tutorials, and seeing that save has sure helped me understand!

Could you add screenshots to show how to do some basic set-ups? Or perhaps a guide to go along side that save so you can describe what each element does (for those who do not understand how the combinators are used)

Things like checking for the trains/cargo wagons being -1, I still do not have a clue what those change to when items are detected?

Also, in the config for the trains, it would 1. be great to split it up a bit better and 2. explain that the signal is not if the path is directly clear, but instead the circuit signal (perhaps an information window)

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

Doing things with combinators inefficiently is easy (relatively speaking). Doing it efficiently? Not so easy. There are oddities like red + green wire implicitly adding inputs (which in certain cases allows a single combinator to work with 4 distinct inputs).

I've been thinking of building a superoptimizer for combinators. Very simple, "just" generate all possible combinations of combinators (with restrictions relaxing as more are tried, in a semi-diagonal manner) and feed inputs to them, weeding out those that don't work. Keep track of what input set killed a certain network, and try inputs most-killed-by-input first, then, depending on the input size, either sequentially through all remaining or randomly a bunch of times then output for a human to check and either validate or provide a counterexample. (Or potentially even to feed to a SAT solver.)

But I need to play around with combinators a bit more first. It'd be a shame to code something only to find that I coded the combinators wrong.

Also: it'd be handy to be able to specify what circuit value a stop in a train line reacts to. So I could have multiple train lines running through a single stop controlled independently as to where to go.

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

I'm playing linear Factorio, with just enough height to have a proper train loop, but no more. As such, I have 1 train loop that all my trains run on, with parallel tracks for stations. As such, I need to keep the main loop as uncongested as possible. This poses problems when I have multiple trains that stop at a station. "Ideally" (that is, within the constraints of mods in Factorio currently), I would like to have the following happen for (most) stops:
  • If the current train is full / empty (depending on the station and train line), send it to stop 1 in its line.
  • If the current train cannot fill / empty any more (ditto), or if there is a train waiting to come into the station, send it to its next stop.
I have something that mainly works for this. It's a little clunky, but boo hoo. However, there are two particular problems.
  • In order to detect that there is a train waiting for the station, the only way I've come up with is to have a pre-station placed just before the station that all trains go to before heading to the station proper, but this requires all trains to stop and doubles the length of the station required.
  • There's no way that I know of to differentiate between trains on different lines (well, that's practical at least. Technically I could have every train hold a different unique item or something I suppose). It'd be wonderful if you could specify what signal a particular line responds to, as opposed to just the entire station.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.11] SmartTrains 0.3.69

Post by Choumiko »

SmartTrains 0.3.69
  • updated for Factorio 0.12.11
  • added interface for de-/activating SmartTrains without removing it
To de-/activate use

Code: Select all

/c remote.call("st", "deactivate")
/c remote.call("st", "activate")
This way you don't loose your trainlines/settings from SmartTrains. Mainly done so that i can more easily see the performance difference, but should also allow you to disable it in case off errors/bugs until they are fixed.
The Lone Wolfling wrote:
  • If the current train cannot fill / empty any more (ditto), or if there is a train waiting to come into the station, send it to its next stop.
How would you decide whether a train can not fill/empty anymore? The "Depart" function of SmartTrains sends the train to the next station if it cargo hasn't changed for a certain amount of time. Is that what you mean? Right now this only works on a per line basis (i'm already planning on making it an option for each station individually).
The Lone Wolfling wrote:
  • In order to detect that there is a train waiting for the station, the only way I've come up with is to have a pre-station placed just before the station that all trains go to before heading to the station proper, but this requires all trains to stop and doubles the length of the station required.
  • There's no way that I know of to differentiate between trains on different lines (well, that's practical at least. Technically I could have every train hold a different unique item or something I suppose). It'd be wonderful if you could specify what signal a particular line responds to, as opposed to just the entire station.
How about a signal that can be hooked up to the circuit network outputting it's state? depending on where you place it, the state would/could have different meanings, if you place a bunch of them it would even tell you how many trains are waiting.
Seems like another special signal would be needed that outputs the linenumber of the train at the station.

With these signals you could do the "Go to station 1 (or station Y) when full/empty or x trains waiting" depending on the line the train is on.
Detecting if a train is full for single item cargo can be done already, for mixed cargo with possibly filtered slots yet another signal would be needed.
It certainly sounds interesting.

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.11] SmartTrains 0.3.69

Post by The Lone Wolfling »

Choumiko wrote: How about a signal that can be hooked up to the circuit network outputting it's state? depending on where you place it, the state would/could have different meanings, if you place a bunch of them it would even tell you how many trains are waiting.
That would be wonderful.
Choumiko wrote: Seems like another special signal would be needed that outputs the linenumber of the train at the station.
I would prefer another solution. That method has race conditions based on how quickly the circuit reading the line # updates compared to the ones updating which station to go to. It can be worked around, but is very clunky and adds even more combinators as opposed to the "line A reads item X, line B reads item Y" solution.

It also has other problems even beyond that (e.g. if you add / delete / modify another line you may have to update every single station with one of these signals, unless I'm mistaken as to what you mean by line number. Ditto, if you have multiple lines that want the same next station you'll still need an additional combinator for every line.)

Let me put it this way: it would technically work, but in practice it'd be so clunky that I doubt I'd ever use it.
Choumiko wrote: Detecting if a train is full for single item cargo can be done already, for mixed cargo with possibly filtered slots yet another signal would be needed.
It certainly sounds interesting.
You can already do this, although it's clunky.. Take advantage of combinators not updating instantly - if you hook up your station to a passthrough combinator reading X and also directly to a comparator combinator set to output when the delayed signal is greater than the non-delayed X one, it'll pulse every time items of type X are removed from the train. (Swap the comparator and you'll get it pulsing every time items are added to the train instead). Connect that to a monostable, and you've got your signal. For multiple items, you either set it to any, or make one pulsar for each item type and feed them all to the monostable.

The problem with the current "go when full / empty" option is that it doesn't interact well with choosing what station to go to next (there's no good way I know of to get it to go to a different station when empty using said option. Or rather, I have been unable to come up with one that doesn't have a race condition)

(By the way: I don't suppose it's possible to detect when there have been changes to the schedule of a train on a line and pop up something asking if you want to update the line? I forget to delete / recreate the line annoyingly often, and as such end up with my changes silently discarded.)

Post Reply

Return to “Mods”