Welcome to the forum   
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post in this topic Go to first unread post in this topic
Offline einotuominen  
#1 Posted : 20 February 2024 10:18:39(UTC)
einotuominen

Finland   
Joined: 19/09/2022(UTC)
Posts: 383
Location: Kaarina
Hi,

I've been playing around with Rocrail's XML scripts a bit, but never used things like variables in them and so on.

Previously I've had a startup and shutdown scripts per loco. What the script does is that it turns on the engine, lights, etc etc. Shutdown is obviously the opposite.

Having a script per loco is a bit much as the action list quite quickly becomes very cluttered of stuff and it is hard to manage. Rocrails user interface is also like the UI that ADSL modems had back in the 90s... Bad and slow to use.

So the question is, how would I create single scripts where the loco in question would be passed as a variable?

In addition, since I have Märklin and ESU decoders, the function mappings differ a bit. For example on ESU the engine is at F8 while in Märklin it is at F2. This would mean that the XML script would need to have some way of identifying something of the loco and make a condition.

Having conditions for each individual loco would also suit me, but I'd just like to have everything in the same XML file.

How would this be achieved?

-Eino
Offline pederbc  
#2 Posted : 20 February 2024 11:29:52(UTC)
pederbc

Sweden   
Joined: 11/06/2007(UTC)
Posts: 182
Location: Eslöv, Sweden
Hi Eino,

I’m using Traincontroller myself so I have no experience in Rocrail. But in Triancontroller you can create aliases of the functions. For example I can create a virtual function ”loksound”, and then on each loco assign a real function to this virtual function. Then in scripts etc use this virtual function instead. Very convenient. Can you check if this functionality exists in Rocrail as well? I have created virtual functions for lights, headlights, wagon lights, horns etc.

Peder
thanks 1 user liked this useful post by pederbc
Offline JohnjeanB  
#3 Posted : 20 February 2024 12:01:09(UTC)
JohnjeanB

France   
Joined: 04/02/2011(UTC)
Posts: 3,138
Location: Paris, France
Hi Eino
Originally Posted by: einotuominen Go to Quoted Post
So the question is, how would I create single scripts where the loco in question would be passed as a variable?

In addition, since I have Märklin and ESU decoders, the function mappings differ a bit. For example on ESU the engine is at F8 while in Märklin it is at F2. This would mean that the XML script would need to have some way of identifying something of the loco and make a condition.

Having conditions for each individual loco would also suit me, but I'd just like to have everything in the same XML file.


Very interesting questions indeed and I am sorry not to know the answers.
Here is the little I think I know:
1- when creating an Action, to get an ACTION started, there is only a "Path" to be indicated but no space for parameter passing.
2- in an XML program one may define a VARIABLE that may be used by others (sort of PUBLIC variable) that anyone can read or update.
3- there is a possibility for an XML program to look into Rocrail's own registers, data tables, etc

I wrote some programs to look into Rocrail's data table for instance to know the occupation of a staging block or to know which locos were on the layout etc.
Closer to your needs I have a program to start the layout:
- locate the position of each loco
- decide to turn ON or OFF the lights and sound depending if the locos are on a route, in a shed or not on the layout at all. This is done by exploring Rocrail tables
- also configure the specific fonctions of cars
Here it is. It may help you create your own program.
Here ROCRAIL's table lclist is used to extract the position of each loco
0 AK Licht on V4.zip (2kb) downloaded 14 time(s).
There are many other Tables in Rocrail that may be of insterest to read & analyse (Block list, Staging block list, Tour list, Action list
Of course, you are not allowed to change values into Rocrail files because one information is written in multiple places and since you don't know the exhautive list, then better refrain from doing it.

Cheers
Jean
thanks 1 user liked this useful post by JohnjeanB
Offline Martti Mäntylä  
#4 Posted : 20 February 2024 12:16:14(UTC)
Martti Mäntylä

Finland   
Joined: 15/11/2018(UTC)
Posts: 398
Location: Uusimaa, Helsinki
This is the XML macro I use:

Code:
[img]<?xml version="1.0" encoding="UTF-8"?>
<xmlscript>
    <fn id="%lcid%" fndesc="Lights" fncmd="on"/>
    <sleep time="2000"></sleep>
    <switch var="%lcid%">
        <case val="BR 103 137-6">
            <fn id="%lcid%" fndesc="Cockpit lights" fncmd="on"/>
            <sleep time="2000"></sleep>
            <fn id="%lcid%" fndesc="Front panto up" fncmd="on"/>
        </case>
        <case val="BR 01 147 H">
            <fn id="%lcid%" fndesc="Steam machine" fncmd="on"/>
            <sleep time="200"></sleep>
            <fn id="%lcid%" fndesc="Firepit" fncmd="on"/>
            <sleep time="200"></sleep>
            <fn id="%lcid%" fndesc="Smoke" fncmd="on"/>
            <sleep time="2600"></sleep>
        </case>
    </switch>
</xmlscript>[/img]


The macro is executed by an event associated with the "depart" state change of a block. The variable "%lcid%" contains the identifier of the locomotive currently in that block. The function names are the ones used in the locomotive description ("Functions" tab).

The trick is to figure out which preset variables are available from Rocrail. Rocrail documentation keeps this information well hidden, but the page https://wiki.rocrail.net/doku.ph...alling&s%5B%5D=block gives some hints. You can also pass parameters to macros if needed.
- Martti M.
Era III analog & digital (Rocrail, CAN Digital Bahn, Gleisbox/MS2, K83/K84), C & M tracks, some Spur 1
thanks 1 user liked this useful post by Martti Mäntylä
Offline Martti Mäntylä  
#5 Posted : 20 February 2024 13:17:00(UTC)
Martti Mäntylä

Finland   
Joined: 15/11/2018(UTC)
Posts: 398
Location: Uusimaa, Helsinki
I must expand my reply regarding parameter passing to XML, because it is fairly unobvious.

The parameters (separated by commas) to be passed must be given in the action control definition, see https://wiki.rocrail.net/doku.ph...=actionctrl-en#parameter. The "parameter" field in the action itself (https://wiki.rocrail.net/doku.php?id=actions-en) is used for other purposes.

In the XML macro, the given parameters are available as "%param1%, %param2%, ...".

Just like Jean said, one can also pull information from Rocrail tables, such as
Code:
<query vr="lcid" table="bklist" id="Asema_2b" get="locid"/>

for getting the identifier of the loco currently occupying a certain block.
- Martti M.
Era III analog & digital (Rocrail, CAN Digital Bahn, Gleisbox/MS2, K83/K84), C & M tracks, some Spur 1
thanks 1 user liked this useful post by Martti Mäntylä
Offline einotuominen  
#6 Posted : 20 February 2024 13:27:00(UTC)
einotuominen

Finland   
Joined: 19/09/2022(UTC)
Posts: 383
Location: Kaarina
Originally Posted by: Martti Mäntylä Go to Quoted Post
I must expand my reply regarding parameter passing to XML, because it is fairly unobvious.

The parameters (separated by commas) to be passed must be given in the action control definition, see https://wiki.rocrail.net/doku.ph...=actionctrl-en#parameter. The "parameter" field in the action itself (https://wiki.rocrail.net/doku.php?id=actions-en) is used for other purposes.

In the XML macro, the given parameters are available as "%param1%, %param2%, ...".


Thanks!

Where exactly in the block details this action is to be associated with the depart? Obviously what I'd write to the param field in this dialog: https://wiki.rocrail.net...=actionctrl-en#parameter would simply be %lcid% ?

So the whole thing would be dynamic then? Everytime a loco departs the block that triggers this action the script is run and the loco id is passed to the script in the variable %lcid% ?

-Eino

thanks 1 user liked this useful post by einotuominen
Offline einotuominen  
#7 Posted : 20 February 2024 13:29:51(UTC)
einotuominen

Finland   
Joined: 19/09/2022(UTC)
Posts: 383
Location: Kaarina
Originally Posted by: JohnjeanB Go to Quoted Post


I wrote some programs to look into Rocrail's data table for instance to know the occupation of a staging block or to know which locos were on the layout etc.
Closer to your needs I have a program to start the layout:
- locate the position of each loco
- decide to turn ON or OFF the lights and sound depending if the locos are on a route, in a shed or not on the layout at all. This is done by exploring Rocrail tables
- also configure the specific fonctions of cars
Here it is. It may help you create your own program.
Here ROCRAIL's table lclist is used to extract the position of each loco
0 AK Licht on V4.zip (2kb) downloaded 14 time(s).
There are many other Tables in Rocrail that may be of insterest to read & analyse (Block list, Staging block list, Tour list, Action list
Of course, you are not allowed to change values into Rocrail files because one information is written in multiple places and since you don't know the exhautive list, then better refrain from doing it.

Cheers
Jean


Thanks Jean, this XML of your's has got great examples for a lot of purposes!

Can't wait to start scripting/automating my new layout... (can't wait do the scenery as well... Endless work list... angry wife BigGrin )

-Eino

Offline Martti Mäntylä  
#8 Posted : 20 February 2024 13:38:40(UTC)
Martti Mäntylä

Finland   
Joined: 15/11/2018(UTC)
Posts: 398
Location: Uusimaa, Helsinki
Like this:

UserPostedImage

There is no need to place the %lcid% as a parameter, it is an automatically set Rocrail variable available in many (but not all, the details confuse me too) cases. The "locomotive" field is filled by Rocrail, no need to touch it.

Yes, the whole thing is automatic. Whenever a loco leaves the block (and launches the "depart" event by doing so), the action control causes the action to take place and the XML macro is run. The identity of the departing loco is available in the Rocrail variable %lcid%.
- Martti M.
Era III analog & digital (Rocrail, CAN Digital Bahn, Gleisbox/MS2, K83/K84), C & M tracks, some Spur 1
Offline einotuominen  
#9 Posted : 20 February 2024 14:09:38(UTC)
einotuominen

Finland   
Joined: 19/09/2022(UTC)
Posts: 383
Location: Kaarina
Originally Posted by: Martti Mäntylä Go to Quoted Post
Like this:

UserPostedImage

There is no need to place the %lcid% as a parameter, it is an automatically set Rocrail variable available in many (but not all, the details confuse me too) cases. The "locomotive" field is filled by Rocrail, no need to touch it.

Yes, the whole thing is automatic. Whenever a loco leaves the block (and launches the "depart" event by doing so), the action control causes the action to take place and the XML macro is run. The identity of the departing loco is available in the Rocrail variable %lcid%.


Got it. Thanks. Yes it's a bit confusing that there is a locomotive drop down there and it has a value selected too.

-Eino

thanks 1 user liked this useful post by einotuominen
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

| Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.560 seconds.