Automatic signal problem

78 views
Skip to first unread message

Nathan

unread,
Jul 20, 2026, 5:27:13 PMJul 20
to Traindir3

Hello everyone,

I'm still working on a belgian signalling package but I'm facing a last (?) problem. In a specific belgian line, you have an automatic signal that onlye have red or green as possible aspects. This signal is located before a signal that may take the red, green or yellow_yellow aspects.

When the next signal is red, aspect of the signal must be red.
When the next signal is yellow_yellow or green, aspect of the signal must be green.

When the aspect of the next signal changes to red, aspect of the signal must be red but when doing so, aspect becomes red but the track is still reserved. Is there a solution so that the track before is not reserved anymore if the signal is automatically set to red when the next signal becomes red ?

You will find the script I use hereunder and two pictures to illustrate the situation.

Thank you for your answer :) !

--

# N.Gomrée 06/01/2018, based on P.Rosati RFI pack

Aspect: red
IconE: NN_rb_E.xpm
IconW: NN_rb_W.xpm
IconN: NN_rb_N.xpm
IconS: NN_rb_S.xpm
Action: stop

Aspect: green
IconE: NN_gb_E.xpm
IconW: NN_gb_W.xpm
IconN: NN_gb_N.xpm
IconS: NN_gb_S.xpm
Action: proceed

# INITIAL ASPECT

OnInit:

.aspect = red
.fleeted = 1
end

# USER CLICKED ON THE SIGNAL

OnCleared:

if next.aspect = red or next.aspect = red_white or next.aspect = red_white_Rx or next.aspect = red_white_Rxx
.aspect = red
return
end

if next.aspect = yellow_yellow or next.aspect = yellow_green
.aspect = green
return
end

if next.aspect = green or next.aspect = green_yellow
.aspect = green
return
end

if next.aspect = yellow_yellow_Rx or next.aspect = yellow_yellow_Rxx or next.aspect = yellow_yellow_Rxxx or next.aspect= green_Rx or next.aspect = green_Rxx or next.aspect = green_Rxxx or next.aspect = green_yellow_Rx or next.aspect = green_yellow_Rxx or next.aspect = green_yellow_Rxxx or next.aspect = yellow_green_Rx or next.aspect = green_yellow_Rxx or next.aspect = green_yellow_Rxxx
.aspect = green
end
end

# ANOTHER SIGNAL CHANGED ASPECT

OnUpdate:

if .aspect = red
return
end

if next.aspect = red or next.aspect = red_white or next.aspect = red_white_Rx or next.aspect = red_white_Rxx
.aspect = red
return
end

if next.aspect = yellow_yellow or next.aspect = yellow_green
.aspect = green
return
end

if next.aspect = green or next.aspect = green_yellow
.aspect = green
return
end

if next.aspect = yellow_yellow_Rx or next.aspect = yellow_yellow_Rxx or next.aspect = yellow_yellow_Rxxx or next.aspect= green_Rx or next.aspect = green_Rxx or next.aspect = green_Rxxx or next.aspect = green_yellow_Rx or next.aspect = green_yellow_Rxx or next.aspect = green_yellow_Rxxx or next.aspect = yellow_green_Rx or next.aspect = green_yellow_Rxx or next.aspect = green_yellow_Rxxx
.aspect = green
end
end

end

Signal green.bmp
When next signal is green, .aspect = green.

Signal red.bmp
When next signal is red, .aspect = red but the track is still reserved.

Paolo Rosati

unread,
Jul 21, 2026, 4:08:35 AMJul 21
to trai...@googlegroups.com

Hi Nathan,

    the reservation of the track occurs depending on the action associated to the aspect, not on the colours shown by the aspect itself or on its name. 

Action: stop means signal is unclear: trains cannot pass the signal and the track after it is free.

Action: proceed or Action: speedLimit nn mean signal is clear: trains can pass it and track after it is reserved.

Action: none means the signal is transparent (typically a distant): trains can always pass it and track reservation is controlled by the nearest previous signal that shows an aspect with an action that is not none.

The default red and green aspects are associated to the stop and proceed actions by convention, as the simulator can associate any action to any aspect name.

In the signal script you change aspects only between those with the same action, as clearing and unclearing is usually done externally by the player or other scripts. You can simulate a click on the signal to force its clearing or unclearing even inside the signal script, but then you have to check if the action is possible or was successful (whichever check is easier), and set or reset the aspect accordingly to keep it consistent with the track reservation, as the program will not do those checks on your behalf. 

Normally the program will check if the clearing / unclearing action is possible, and if not nothing is executed in the signal script.

Paolo R.

--
Se non desideri piú essere abbonato a questo gruppo, invia un messaggio a traindir3+...@googlegroups.com
Per ulteriori opzioni, visita il gruppo alla pagina http://groups.google.com/group/traindir3?hl=it
---
You received this message because you are subscribed to the Google Groups "Traindir3" group.
To unsubscribe from this group and stop receiving emails from it, send an email to traindir3+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/traindir3/61bf761a-a33e-4e9b-bf94-1455053be882n%40googlegroups.com.

Nathan

unread,
Jul 21, 2026, 8:49:54 AMJul 21
to Traindir3
Thank you for your answer Paolo.

In this case, if the red aspect is associated to the STOP action, why is the track still cleared after the signal became red ? Because there is not a click on the signal but only a change of the aspect of the next signal ? How could I emulate the fact that when the next signal becomes red, it's like the player clicked on the signal to put it red and so uncleared the track ?

In the actual script, the signal becomes red when the next signal becomes also red but the track stays cleared.

Thank you for your answer !

Nathan

Paolo Rosati

unread,
Jul 21, 2026, 10:38:04 AMJul 21
to trai...@googlegroups.com

Hi Nathan,

    because when you force the aspect in a script the program just does that. It doesn't apply the new action if it's different. This is for flexibility: the idea is that you can do almost everything in scripts, but the program doesn't help you, you must take care of everything and keep everything consistent. This power is not easy to use - some scripts in the package are more than a thousand lines long - but it's actually very very powerful.

To clear / unclear a signal in a script you set the click property of that signal to 1.

The click is ignored if the current aspect action of that signal is none, otherwise if the (un)clearing is possible, the track is (un)reserved and the OnClear or OnUnclear functions of that signal's script are executed, depending on its current aspect action being stop or something else. Those functions are responsible to set an aspect consistent with the new condition (cleared or uncleared), and then the usual OnUpdate cycle is executed on all sygnals to update their aspect if needed. Only after this the execution returns to the point where you set the click property to 1, to continue from where it was.

Needless to say, avoiding infinite loops in all of this is again up to you, and if you trigger a loop the program will crash instantly, leaving you to debug the script without seeing what it was doing before the crash.

Have a look at the scripts in the package, as interlocking with the following signal is simulated in this way (in Italy sometimes two consecutive signals cannot be cleared together, for example on station tracks where transit without stopping is not allowed).

You can use fake aspects - used only during the script execution - to intercept and distinguish if the (un)clearing comes from your script or from the player, and to avoid loops. 

Writing a signal package is not an easy task: the last Italian package took 5 years to be developed...

Paolo

Nathan

unread,
Jul 24, 2026, 11:54:06 AMJul 24
to Traindir3
Hello Paolo,

Using the .click = 1 property works partially : thanks to this, the signal becomes red when the next signal becomes red (pictures 1 and 2), which is correct.

Signal 1.bmp
Picture 1 - Next signal becomes green so the signal becomes green.

Signal 2.bmp
Picture 2 - Next signal becomes red so the signal becomes red (using .click = 1 property).

But when the next signal becomes green again, the signal becomes green but not the track, like the green aspect wasn't associated to any action but in the script, it is associated with the action "proceed" (picture 3). Any solution to this ?

Signal 3.bmp
Picture 3 - Next signal becomes green again but the track doesn't become green.

I know that developping a signal package takes a lot of time : I've been working on a belgian one since 2020 :p !


Thank you for your answer :)

Nathan

Paolo Rosati

unread,
Jul 24, 2026, 1:12:17 PMJul 24
to trai...@googlegroups.com

Hi Nathan,

    as red and green have different actions you have to use the click = 1 clause to change between them, in both directions.

You cannot set just the aspect to green if it's red, and you cannot set just the aspect to red if it's green.

Something like

if .aspect = red and next.aspect != red

    .click = 1                    # This clears the first signal (possible only if path to next signal is set and free)

else    

if .aspect != red and next.aspect = red

    .click = 1              # This unclears the first signal (always possible)

end

end

Paolo

Nathan

unread,
Jul 26, 2026, 3:02:16 PMJul 26
to Traindir3
I think I see a solution for the problem, altough it's more complicated than I tought.

Another question : I've on this scenario a main signal followed by an avert one and then by a main signal. In the main signal script, I've a line that looks if the next script is the script of the avert signal and if so, put a defined aspect. But I've the impression that the script doesn't look to the avert signal because all of the aspects are associated with the action "none". When the aspects of the avert signal are associated with the action "proceed", it works.

Here's the script but I don't understand what's wrong in it. Is it only because the avert signal is ignored by the script (next signal refers to the next main signal or the next signal with an action other than none ?) ?

if next.script = "SNCB_avert_V100.tds" or next.script = "SNCB_avert_V110-120.tds" or next.script = "SNCB_avert_V130.tds" or next.script = "SNCB_avert_V140.tds" or next.script = "SNCB_avert_V160.tds"

if next.aspect = yellow_yellow or next.aspect = yellow_green
if next.nextLength < 700
.aspect = green_yellow
else
.aspect = green
end
else
.aspect = green
end
return
end

Thank you for your help !

Paolo Rosati

unread,
Jul 26, 2026, 6:07:23 PMJul 26
to trai...@googlegroups.com

Hi Nathan.

You're right.

Approach signals - any signal showing an aspect with action none - are transparent to other signals (and to trains) so the next clause doesn't see them. You have to use nextApproach in this case; it will see the next signal if it's an approach one.

next will see the next non approach signal no matter how many approach signals are in between

nextApproach will see just the first next signal, and only if that signal shows a none aspect.

This means that in generic scripts you have to check all the approach aspects first - if they are meaningful - and only then you can check normal aspects, rememberig that they may occur after any number of approach signals.

Paolo

Reply all
Reply to author
Forward
0 new messages