Identifing loco within Consist

Identifing loco within Consist

Postby SteveP_trains » Mon Nov 24, 2025 3:07 pm

Hi All
Hope someone maybe able to help!

I have a Carriage LUA script that identifies whether there is a vehicle ahead or behind itself so as to work out if the carriage is coupled or not.
If coupled, then I switch on the Node to make the extended Corridor connection visible - if not coupled then I show the shortened Connector (with the appropriate electrical connections as well)

What I now need is to identify when the carriage is couple to the LOCO so that I show the short Corridor Connection + No electrical connection.

Any ideas how I can tell if the next vehicle is a carriage or loco?? (Steam loco and carriages BTW)
Thanks

Steve (SPRAILWAYS)
SteveP_trains
Full Time Fireman
 
Posts: 77
Images: 1
Joined: Mon Oct 05, 2015 6:16 pm
Has thanked: 3 times
Been thanked: 11 times

Re: Identifing loco within Consist

Postby AndiS » Tue Nov 25, 2025 11:53 am

Since you already have the script, all you need is make the short connection show initially and when the answer from the neighbour arrives, you hide the short one and show the connected one. The engine will not answer.

Alternatively, you ensure that all the engines run a similar script and answer "I am an engine". Then you save showing the short connection initially and only show something on receipt of a message and the message parameter tells you what to show.

In all cases you will want to keep a variable to remember whether you already showed something to make it a little less inefficient.

I found this link before I realised that you are already there anyway:
https://www.trainsimdev.com/forum/viewt ... 6480#p6480
AndiS
Top Link Driver!
 
Posts: 810
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 270 times
Been thanked: 320 times

Re: Identifing loco within Consist

Postby SteveP_trains » Thu Nov 27, 2025 11:55 am

Thanks Andy
Yes, I was working through that LUA script link that you supplied. I'll need to read it again to see how the "I am an Engine" response would work.
However, "......... when the answer from the neighbour arrives, you hide the short one and show the connected one. The engine will not answer" - Not sure what you mean by 'The engine will not answer'?

I think my simple "Is there a vehicle ahead or behind" includes the loco?? Or it seems to be in the result I see on screen.

Anyway thanks for reply - I'll work through your suggestions.

Regards
Steve (SPRAILWAYS)
SteveP_trains
Full Time Fireman
 
Posts: 77
Images: 1
Joined: Mon Oct 05, 2015 6:16 pm
Has thanked: 3 times
Been thanked: 11 times

Re: Identifing loco within Consist

Postby AndiS » Thu Nov 27, 2025 6:04 pm

Not sure what you mean by 'The engine will not answer'?


In OnConsistMessage you see that if the message is WAGENTYP_ID (carriage type) and the argument (called parameter in the Kuju documentation) is 4, then it sends the same message on(?) using SendConsistMessage with the same value for direction.

I cannot surely remember about the direction. When sending a message, 1 means "to the back". But in OnConsistMessage it could mean "from the back". I am not totally sure at the moment.

Anyway, what I meant is: If your carriages all send a message back and the receipt of this message triggers showing the connection, and if the engine does not run such a script, then this answer will never be received from the engine and the corridor connection will remain in the shortened/unconnected state.
AndiS
Top Link Driver!
 
Posts: 810
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 270 times
Been thanked: 320 times


Return to Scenario Creation

Who is online

Users browsing this forum: No registered users and 2 guests