Super Sessions for Trainz Railroad Simulator
In 2020, we stumbled upon Trainz Railroad Simulator by chance. After a few days of having fun with it, we got bored with driving a single train without ever encountering any other.
However, toying with the settings and UI, we discovered that, besides allowing you to manually run a single train, it contains a (very!) basic scripting interface that allows automation of trains.
After some more toying, it became clear that this is actually a world-building app. None of the Mac AppStore's description mentioned this…
So we went to work. We built ourselves a route specifically designed to accommodate a lot of traffic – One station with 10+ platforms, a few pass-through tracks, a freight section with multiple loading docks and a biggish yard, plus a hump-yard. We connected the station in four different directions to ~5km quadruple track (a fast and a slow track for all four of the station's incoming directions and the same for its outgoing traffic).
Thus we had large station connected to 16 tracks in total. We attached portals to the ends of all 16 tracks, to easily automate incoming and outgoing traffic. We relied mainly on the built-in commands, like Drive To/Via, Navigate To/Via, Couple To, Runaround, etc.
Making use of basic triggers, adding and subtracting to SVars, their values rendered through the CustomHUD, we could keep a clear count. We found that we could easily up the portals' output to the point where we were consistently running an average of 60 random trains simultaneously, for hours on end.
But always, after 'a while', trains would get lost, or partly derail. Neither of which could be ignored, because it would always result in the blocking of other traffic.
We systematically tried absolutely everything we could think of, without ever getting Trainz to behave reliably. It seemed that the only possible cause was that we had built some sort of mistake into our route. But what?
So we decided to try if we could build a similar session on other people's routes. We spent about a year on this. Building sessions on about five routes built by others. Mostly on routes that the vendor distributed along with the app, assuming that surely at least those would not contain mistakes, right? We learned that, no matter which route we tried, trains would derail, get lost, etc.
The good thing was that this taught us that the problem was not caused by anything we had done wrong in our own route. Of course we still had no solution, but at least by now we had narrowed the problem down to (most likely) be in the session-building technique itself.
In fact, we found that there are several crucial bugs in Trainz that ensure that any use of its built-in 'AI' guarantees failure. Given that by then we had already reported dozens of bugs, only to find that the vendor simply ignores any and all bug reports, our only option was to try to find workarounds…
In the end, pguy's MissionCode turned out to be a crucial part of the answer. Not that it was an easy solution. MissionCode offers many options, each of which can be the crucial solution for a given situation, and each of which needs to be fully understood or it won't give you the result you're looking for. It took us about a year of (re)building several sessions with MissionCode to get comfortable with it. But, once we did, we finally got Trainz to run our sessions (somewhat) reliably.
This is not to say that all this takes is MissionCode. While MissionCode provides crucial functionality, it does not provide any and all functionality. We still needed other tools/commands/scripts. But now that we understood Trainz' bugs, we were able to select the tools/commands/scripts that can be used safely in specific conditions, and avoid those that cannot.