Multiple Eras
Scripts can be used to switch a layout period, for example the same layout can be used to switch from a 1960′s era model with diesels in green livery to 1980′s with diesels in blue livery, or to a modern era with multiple units in all sorts of liveries!
See Lickey for an example layout.
On many layout projects, I can’t decide what period to model: steam / green diesels / blue diesels / modern multiple tocs etc. So why not model them all? Well for one reason, it would be difficult with a large layout to have to keep multiple copies of the layout - suppose I spend a couple of hours sorting out the terrain in the steam era model - I really don’t want to have to do it all again on the other era layouts.
So, how about using a script to make the changes. As of build #101.5.2 this is now possible.
Document macros
The first step is to create suitable entry points, I used the new document macro facility to add functions in the document script and make these available in the program’s tools menu:
Macro_GreenEra()
{
debug.clear();
debug.printL("Green");
iMode=0;
Document.RunGlobalScripts();
}
etc
So, when the GreenEra script is called from the tools menu, this function sets a script global variable (iMode) and calls RunGlobalScripts function. This calls script functions (as below) for each link/node/train/signal in the layout: these functions can retrieve the value of the iMode variable and act upon the link/train etc as appropriate.
OnGlobalLink
OnGlobalLink()
{
node nN=Link.GetPrimeNode();
float x=nN.GetX();
if(iMode==2)
{
if(Link.GetType()=="STDGGE")
{
Link.SetType("Concrete");
if(x>=23610)
Link.SetOHLE(1);
}
}
else
{
if(Link.GetType()=="Concrete")
Link.SetType("STDGGE");
Link.SetOHLE(0);
}
}
The OnGlobalLink function is fairly simple.
For each link, the track type is changed from “stdgge” to “Concrete” (if mode=2, ie when the blue script has been called) and vice versa for the other modes (steam and green).
Additionaly, I want the line to be electrified west of a certain point in the layout (in the blue mode), so the script retrieves the position of the link, and sets the ohle on if appropriate. In green and steam modes, ohle is turned off.
OnGlobalTrain
The train function is more complicated.
OnGlobalTrain()
{
string sRoute=Train.GetRoute();
train tT;
if(iMode==0) // Green
{
if(sRoute=="7F24")
{
Train.SetType("20pg");
tT=Train;
tT++;
tT.SetType("20pg");
tT++;
while(tT)
{
tT.SetType("GWR30TMacawB");
tT++;
}
}
.. etc ..
For each train, and according to the train route and the mode (green/steam etc) the script sets the stock type. Notice how
while(tT)
{
...
tT++;
}
is used to iterate along the train from the lead vehicle to the end, changing each vehicle in turn.
In my example, I have used the train route to determine the vehicle change required, in a larger layout it might be more sensible to change the type based on the stock type rather than the route, eg:
if(Train.GetType()=="37Blue")
Train.SetType("37Green");
if(Train.GetType()=="MK1_bg_TSO")
Train.SetType("MK1_m_TSO");
if(Train.GetType()=="MK1_bg_BCK")
Train.SetType("MK1_m_BCK");
etc
It might also be necessary to change the number of vehicles in the train, and the Train.Append() and DeleteFollowing() functions can be used to achieve this.
OnGlobalSignal
The OnGlobalSignal function is used to change signal types in my example from semaphores to colour lights. A complication here is that whilst it is easy to change to colour light signals:
if(Signal.GetType()=="UQH")
Signal.SetType("UK4");
if(Signal.GetType()=="UQHD")
Signal.SetType("UK4");
it is not so easy to change back: in the above example both the Upper Quadrant Home (uqh) and Upper Quadrant Home and Distant (uqhd) map to a four aspect colour light (uk4), but the same technique cannot be used to switch back since “uk4″ could map to uqh or uqhd. To overcome this I used the Signal.SetID() function to store the sempahore type in the signals id flag and then can use this value when switching to sempahore mode to determine the correct signal type.
Further refinements
- I have not addressed scenery in my example scripts - you might want to change add or remove scenery items when switching eras.
- I have not tried to change the track when switching - but it ought to be possible to change the track, ie add sidings, delete sidings, change routing etc when switching eras.
---
My example scripts can be found with the sample Lickey layout, you will need program build #101.5.2 or later to try them.
MRG 06/08/2013 15:03:27