Can consists assigned to a portal be changed "outside" of in-game portal properties ?

enginerust

New member
Hello, I've been thinking about a project to build a short scenicked stretch of track, with portals on both ends loaded up with consists that will flow each direction. Basically the goal is a railfanning operation where I can just watch the various consists pass. My wish is to load the portals with RANDOM consists that I have built programmatically. I have been working on a program that takes ALL my train vehicles, categorizes them by type, road name, etc and then builds random traains. This part is working well and I can generate a config.txt file to change the contents of existing generic named consists (CON01, CON02, etc). I can load a portal with session edit with these consists, but I of course can see what's in the consists I am loading up. I would like to just be able to create a session, load up the portals with these generic named session one time, and from that time forward, I would want to just change the content of the consists outside of trainz using my program before each game session so that I do not have any idea which types of trains will be coming out of the portals, I want to be completely random with them. I guess my ultimate question is: Is there any way to programmatically change the content of consists that are contained in a portal outside of Trainz session editor ? I hope I explained what I'm looking for here well enough.
 
I hope I explained what I'm looking for here well enough.
Yes, but a better way would be to port your random-train-generator to gamescript, have it spin up a random train inside the session, create the train at a trackmark that is hidden "off-stage" somewhere, and kick it into motion. No need to shut down the simulation to reseed the list of trains.
 
Yes, but a better way would be to port your random-train-generator to gamescript, have it spin up a random train inside the session, create the train at a trackmark that is hidden "off-stage" somewhere, and kick it into motion. No need to shut down the simulation to reseed the list of trains.
Thanks for the tip! Time to learn some TrainzScripting for sure.
 
You are welcome indeed. As for myself, I`m trying to relearn gamescript. I used to do a fair amount of programming in gamescript back in my Trainz 2004/2009/2010 dayz.
 
In respect of random traffic don't forget you can hide short portals in many buildings such as factories, warehouses, workshops and so forth, and by mixing traffic from more than one source and at different speeds such as goods and passenger, it will become even more irregular. I know that the process of just unloading and then reloading UK type container wagons results in random order of available containers being loaded and hence the appearance of a train looking completely different. I don't know about other similar wagons. Peter
 
Some portals can be programmed to emit trains that you design at specified intervals. I haven't tried the gamescript approach.
 
I think I can use the <kuid2:61392:5011:57> "Quick Portal Manager with Timetable standard edition (TANE SP4 and later)" rule to do what I need. I can do a one-time setup of a whole day's worth of scheduled trains (all generically named CON01, CON02, etc). Then, outside of Trainz, before I load and start the session, I can use my program to build all the CONs randomly and when I load Trainz and start the session I'll get those random trains from my portal, different every time! I can do this on each end of the route then sit back under a tree and do some railfanning where every train and day will be different :)
 
Ok, but how will the information make the transition from inside your program to inside Trainz? That is what you started this thread to ask about, isn`t it? What is your solution to that part of the problem?
 
That’s what I’ve been thinking about now lol. For now, in CM I can open all the CONs in to edit, then hopefully get my program to walk through each CON directory editing each config.txt with the randomly generated trains then once the program is done submit all the edits in CM. If that works then later I’ll figure out how to do it with no interaction except starting my program hopefully. I’m still working on the procedures for generating realistic trains using the program. Taking into account train types, road names and realistic structure. That is definitely a WIP but is doable 🤞 oh and also categorizing in a database all the “train vehicles” I have downloaded and available to build trains from.
 
Ah, I know a better way: Build yourself a batch file as follows:
  1. Launch Trainz. It must be already running for the following to work.
  2. Make your batch file sleep long enough for the Trainz Launcher window to open.
  3. Use the trainzutil.exe program to automatically open-for-edit those assets.
  4. Run your program.
  5. Use the trainzutil.exe program to automatically submit your modified assets.
  6. If there is a way to do so, use trainzutil.exe to launch your session.
This should work without as much effort on your part.

Edit: what language is your program? I might be able to help you generate the data directly into the open-for-edit asset directories.
 
That's a great idea! I didn't even think (or really know) about trainzutil lol... sounds like that should work I hope... as for my program up till now I was working with visual basic in a spreadsheet, I could copy a bunch of train vehicle kuids from CM and then paste them into a page in my spreadsheet and click a button and it would build a correctly formatted consist that I could copy and paste into a reusable consist asset, submit the edit and start up trainz and could load the consist containing exactly what I had put in it. That was step one lol ... the next step was trying to load a portal with the consist...I noticed that when I selected the consist, it was saved in the portal as individual train vehicles. Even if I changed the consist using my spreadsheet to be different but save as the same name, when I'd edit the portal I noticed it still had the original train vehicles... that's when I started this thread after searching and trying a few things that didn't work. Even using a couple of the portal managers I tried didn't work. It wasn't until OddRails mentioned about portals that can emit trains of my design on a schedule that I located the <kuid2:61392:5011:57> "Quick Portal Manager with Timetable..." and that did exactly what i wanted... it only saved the name of the consists, not the content... so I could change the content before each session and it would change in session. Now that that part of the plan seems to work, now I have to knuckle down on expanding the program and come up with procedures for reading my collection of train vehicles and building realistic trains. I'm not a big programmer, I learned in turbo pascal decades ago lol ... but it doesn't have to be sophisticated, it will mainly be reading text files into arrays, building trains and writing out config.txt files.
 
I am quite familiar with Beginners` All-purpose Symbolic Instruction Code (yes, that`s what the letters officially stand for), having programmed in at least a dozen dialects. Unfortunately, that is not one of them, and I have pretty much no idea how to do direct file-i/o with it. Do you have any other languages at your disposal for this project?

Incidentally, I`m working on a project that will include a custom-coded portal manager. When I get it written (it should take about a month or so before I`m ready to share it), it sounds like it would be almost exactly what you need, only entirely within Trainz. For the record, I was already planning on doing this before I saw your cry for help.
 
You might want to take a look at this.


TNI allows external programs to interact with core Trainz components.

@MasterTracklayer you might be interested in this too.
 
I`ve seen that already. Not for me at this time. I don`t think that @enginerust is in a position to make any use of it either. Go back and re-read what language he is writing his project in for why I think this. That said, I think that he`s done an amazing job to get his project this far along.
 
You might want to take a look at this.


TNI allows external programs to interact with core Trainz components.

@MasterTracklayer you might be interested in this too.
Thanks JCitron ! I will look into that, it does sound like something I could make use of. @MasterTracklayer I often do quick and dirty programming in VBA or yes even AutoHotKey when I’m working on proof of concept of procedures I later expand on. Bottom line, however I get there it will work and do what I want to accomplish. I appreciate the input I’m getting from you and EVERYONE here, let me figure out what works for me or not.
 
Awww, thank you. I tend to not change languages in the middle of a project, as my proof-of-concept typically needs the same resources and limitations as the final program, plus it eliminates the need to translate the code into a different language. It just never occurred to me that you would make such major changes to your project as the language it`s written in. This led me to make assumptions that now appear to be unwarranted. Let you? How could I prevent you? (Not that I would want to.) I do what works for me, you do what works for you. I generally hold that results are more important than methods, within reason.
 
Back
Top