How to: Random Flagstops (Scenario Editor)

General forum for the Cascadian route

Moderator: ricksan

How to: Random Flagstops (Scenario Editor)

Unread postby GreatNortherner » Wed May 01, 2019 4:06 pm

Hi,

With all these many flagstops on our route (and in the GN public timetables), we were wondering if there is a way to replicate this in TS. To make it so that the player won't know by looking at the task list if they'll have to stop at for example Winton, Reiter, or Scenic -- and to make it so that it would be different each time the scenario is run.

I remembered that Wayne Campbell achieved something just like that in his passenger scenarios on the B&O Kingwood Branch route (which is also full of flagstops) and which I thus used as the starting point for my investigation -- and more than that, I learned very much by studying Wayne's work.

And here's how it all works. I'll show the mechanics at work with a simple test scenario that covers all the basics and that should be fairly straightforward to replicate.

1) Prerequisites
  • GN Cascadian Route with Everett expansion
  • good knowledge of the RW scenario editor
  • some basic knowledge of Lua scripting in RW
  • not being afraid to hack your scenario files with a text editor

2) Set Up the Scenario
  1. Create a new Standard Scenario, choose Merritt as the start location and place the scenario marker near the depot.
  2. Place an engine next to the depot and make it the player train.
  3. Next to the player train, place a large object of your choice. Double click on it and have a look at its properties on the right-hand panel window. See the empty text input field on the panel? This is where you can name your object for the scenario's script. In this example, name it "MyMagicObject".
  4. Save your work, exit the scenario editor and return to the main menu.
  5. Download this file:
    TO_for-ScenProp_Bugfixed.xml
    and open it with a good text editor (ConText, Notepad++, or similar)
  6. Open your new scenario's ScenarioProperties.xml in a text editor. Scroll to near the end of file, look for the lines: "<NamedEntity>" and its corresponding closing tag </NamedEntity>. In between the two, you'll see your "MyMagicObject" from before.
  7. Now copy all contents from the xml file you downloaded before and paste them into your ScenarioProperties just before the closing </NamedEntity> tag. Check that you haven't left empty lines, then save the xml file. (Ignore the strange tabulator spacing in the pasted content, RW will take care of that when you next save the scenario).

Script the Scenario
  1. Now go back into RW and load your scenario in the editor.
  2. Add a Trigger Instruction ("pop-up message") to your service. Give it a delay of five seconds. Leave the Trigger Message box empty but enter "TheMagicHappens" into the Trigger Event box.
  3. Set up a new "ScenarioScript.lua" in your scenario's folder.
  4. Paste the following code into your OnEvent function:
  5. Code: Select all
    function OnEvent(event)
      -- Merritt Flagstop Test
      if (event == "TheMagicHappens") then
        flagstoptest1 = math.random(10)       
        -- creates a random int between 1 and 10
        if flagstoptest1 > 4 then
        -- 60% chance for the following
          SysCall ( "ScenarioManager:ShowMessage", "Random Success?", "YES! Train Order Board now at Y/Y. Magic Object has disappeared.", 0 )
          SysCall( "MyMagicObject:setNearPosition", 0,0,0 )             
        -- this moves the named object to the center of the tile (so it's hidden)
          SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","red1",0 )     
        -- MerrittTOeb is another named object and part of the list you pasted into your ScenarioProperties
          SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","orange1",1 )
          SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","green1",0 )
          SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","red1",0 )
          SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","orange1",1 )
          SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","green1",0 )
        else
          SysCall ( "ScenarioManager:ShowMessage", "Random Success?", "NO! Train Order Board at R/R. Magic Object is still there.", 0 )
          SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","red1",1 )
          SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","orange1",0 )
          SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","green1",0 )
          SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","red1",1 )
          SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","orange1",0 )
          SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","green1",0 )
        end
      end
    end
  6. Compile your script in the editor (second button from the right in Timetable View), save your scenario and click play.

And you're done! You should now have a functioning scenario with a 60% chance for the train order signal to switch to yellow/yellow and a 40% chance for red/red.

Here's an upload of the scenario I wrote for this test (script included):
759e5e2d-6f18-49ea-b8e6-202fca3c5886.zip
-- unpack this into your Cascadian route's Scenarios folder: RailWorks\Content\Routes\a078a51f-90eb-41f3-a8b4-0354f66504d2\Scenarios

And here's the complete list of all the flag stop signals that you can use in this fashion after you've pasted the contents of the attached .xml file into your ScenarioProperties file:
TO_sorted-list.txt
.

The ActivateNode command is actually from the signal script but as you can see, it works in the scenario too when called from the SysCall command. Kudos to Wayne for figuring that one out! "1 Head Signal" is the name of the child object in question and is the same for all train order signals on our route. green1/orange1/red1 are the names of the anim states for CLEAR, CAUTION and STOP which you can activate (1) or deactivate (0). You don't actually need to run all three colors, just the ones that need changing (so if train order signal is green by default and you want to switch it to red by script, you'd just have to do ActivateNode for "red1",1 and "green1",0.

Have fun scripting!

None of this would have been possible without the great tutorials on Matt P.'s blog:
http://trainsimlive.blogspot.com/2015/02/

...and the DTG dev docs online collection:
https://sites.google.com/a/railsimdev.c ... C-Overview

Cheers
Michael
You do not have the required permissions to view the files attached to this post.
Last edited by GreatNortherner on Sat Nov 23, 2019 7:34 pm, edited 1 time in total.
User avatar
GreatNortherner
 
Posts: 1586
Joined: Sun Feb 15, 2009 11:19 am
Location: Czech Republic

Re: How to: Random Flagstops (Scenario Editor)

Unread postby GreatNortherner » Wed May 01, 2019 4:12 pm

... and a couple of screenshots from the editor:
20190501211959_1.jpg

20190501213032_1.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
GreatNortherner
 
Posts: 1586
Joined: Sun Feb 15, 2009 11:19 am
Location: Czech Republic

Re: How to: Random Flagstops (Scenario Editor)

Unread postby ozinoz » Thu May 02, 2019 2:29 am

Excellent post - there are sore really smart people out there **!!bow!!**

I am still struggling to get AP's weather to work, so will see how it goes...

*!!thnx!!*

!*cheers*!
ozinoz
 
Posts: 1626
Joined: Fri Feb 20, 2009 1:59 am
Location: Antipodes

Re: How to: Random Flagstops (Scenario Editor)

Unread postby Chacal » Thu May 02, 2019 9:47 am

Thanks Michael. This is quite impressive.
TS2019 may be getting old, but it is still capable of more things than we expect, thanks to people like Wayne and you.

I have added this tutorial to the RWA learning center.
Over the hill and gathering speed
Chacal
Site Admin
 
Posts: 6462
Joined: Tue Jul 05, 2011 1:11 pm
Location: Quebec, Canada

Re: How to: Random Flagstops (Scenario Editor)

Unread postby GreatNortherner » Thu May 02, 2019 11:37 am

Ooh, I've made front page news! *!embar*! Thanks!

Just one additional comment:
The tutorial is written for the GN Cascadian Route with Everett expansion, but can be easily adapted for any route.

Yes... and no. You can absolutely copy this method 1:1 onto another route -- in fact, that's exactly what I did with Wayne's code and discoveries. !*salute*! However, I wouldn't say it's exactly easy.

The critical step is that you must first assemble your own list of named signals (or whatever objects you want to use) for your ScenarioProperties.xml. In the case of signals, this means finding the signal's code block in tracks.bin, figuring out where on the route it is by visiting the tile coords that the signal has in tracks.bin in the route editor, copying its UUID code stuff to your ScenarioProperties, and finally adding the name. In the case of the couple dozen or so train order signals on the Cascadian that was more time consuming than difficult, because I knew what to look for and those train order signal objects are used only as such. But I wouldn't want to do it on a route where the signal in question is in use hundreds of times all over the network.
User avatar
GreatNortherner
 
Posts: 1586
Joined: Sun Feb 15, 2009 11:19 am
Location: Czech Republic

Re: How to: Random Flagstops (Scenario Editor)

Unread postby Chacal » Thu May 02, 2019 12:07 pm

Not exactly easy as you say. This will be for advanced users. I'll add this to the web page.
However I'm thinking they would want to do what you did: randomize one or two signals, out of the dozens on the route.
So the xml file could contains only those few signals.

The link on the web site points to this thread, so anyone interested will also read your caveat.
Over the hill and gathering speed
Chacal
Site Admin
 
Posts: 6462
Joined: Tue Jul 05, 2011 1:11 pm
Location: Quebec, Canada

Re: How to: Random Flagstops (Scenario Editor)

Unread postby awaken1977 » Sat May 16, 2020 11:04 am

Very interesting stuff.
Im trying to implement similar feature in Swiss route. There are special signals for requesting stop, they do not affect traffic, only informational.
It is a special signal with binary indication (white = on, no signal = off)

How can I know, what's the name for signal in particular route? instead of MerritTOeb:1 Head Signal

SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","red1",0 )

signal scripts in this route are encoded and not readable in .out format (commercial add-on, protected from reverse engineering)

any way to debug existing scenarios, to see what signals/object names are activated in the Logmate log?
awaken1977
 
Posts: 335
Joined: Mon Nov 25, 2013 2:40 am


Return to GN Cascadian General

Who is online

Users browsing this forum: No registered users and 1 guest