Hi,
I have a problem with my signal, this problem just happen in one station (Called A station) in my route.
When in a scenario ,when my train need to stop at station A .When my train begin to enter the platfrom ,the signal in front of the platform(exit signal) is open (this is correct ),but when my train stops ,the signal will turn red and even I press TAB ,the signal will never open again. There is no other trains in and out of this station.
Why does this signal turns red?the junction does not change ,the train path passes throuth the junctions and leads to the mainline in the map.
I have to build another line to test the same scene,and there is no such problem.
I have write som Debug print in the signal script but when I open the logmate ,I cannot see any debug print.
So could anyone please tell me how to debug the signal scripts?
BTW I don't write any "train in rear "(train in approach of the signal)scripts in the signal scripts.
Thanks
Fei
How to debug signal ?
Moderator: Moderators
- AndiS
- Very Active Forum Member
- Posts: 6158
- Joined: Fri Sep 23, 2005 4:43 pm
- Location: Jester's cell in ivory tower
- Contact:
Re: How to debug signal ?
If you are using the default scripts, you need to set
DEBUG = true
It is set to false near the definition of function DebugPrint.
Have you altered the default scripts? If so, have you implemented something to close the signal if the train moves in the other direction.
A standing train appears to the signals to move a bit in both directions. To avoid confusion, I check whether speed is greater 0.1 m/s. If this needed for you, show me your code piece and I show you how to integrate the check.
DEBUG = true
It is set to false near the definition of function DebugPrint.
Have you altered the default scripts? If so, have you implemented something to close the signal if the train moves in the other direction.
A standing train appears to the signals to move a bit in both directions. To avoid confusion, I check whether speed is greater 0.1 m/s. If this needed for you, show me your code piece and I show you how to integrate the check.
Re: How to debug signal ?
AndiS wrote:If you are using the default scripts, you need to set
DEBUG = true
It is set to false near the definition of function DebugPrint.
Have you altered the default scripts? If so, have you implemented something to close the signal if the train moves in the other direction.
A standing train appears to the signals to move a bit in both directions. To avoid confusion, I check whether speed is greater 0.1 m/s. If this needed for you, show me your code piece and I show you how to integrate the check.
Hi AndiS,
Thanks for your tips.
Now I have set the DEBUG to true and I can see the print in the logmate .
but it causes the game very slow and sometimes it crashes. Is there any way to just see a special signal debug print?
I wrote the code as follows
Code: Select all
elseif gPrepared == 0 then
gSignalState = STOP
gCabAspect = RESTRICT
if ( TrainState == TRAIN_IN_REAR ) and ( frontDist < 500 ) then
DebugPrint(("DEBUG:NotPrepared"))
end
Another question is the message direction , I have a picture for you
Is my understanding correct?
Today I have not reached the signal I want to test .I will post more information here if I have some progress.
Thanks again
Fei
- AndiS
- Very Active Forum Member
- Posts: 6158
- Joined: Fri Sep 23, 2005 4:43 pm
- Location: Jester's cell in ivory tower
- Contact:
Re: How to debug signal ?
You can simply use Print instead of DebugPrint and leave DEBUG at false.clkgtr wrote:Now I have set the DEBUG to true and I can see the print in the logmate .
but it causes the game very slow and sometimes it crashes. Is there any way to just see a special signal debug print?
For course, this only shows the few messages you add. But this might be what you want.
It helps when you select "clear log" in LogMate every time you start a test - or whenever it makes sense. When the logs become large, LogMate becomes slow. And there is no way to switch off all the tabs you do not need (pathing, runtime error, etc.)
I would assume that TrainState is not TRAIN_IN_REAR if you do not see a message printed.clkgtr wrote:I wrote the code as follows
but it does not seem to work.Code: Select all
elseif gPrepared == 0 then gSignalState = STOP gCabAspect = RESTRICT if ( TrainState == TRAIN_IN_REAR ) and ( frontDist < 500 ) then DebugPrint(("DEBUG:NotPrepared")) end
So you need to explore this.
In Lua, you can easily show numbers together with strings using the concatenation operator:
Print("TrainState is " .. TrainState)
This hard to say because I am not sure I understand your question. I believe you are confused by this:clkgtr wrote: Another question is the message direction , I have a picture for you
Is my understanding correct?
The direction parameter in OnSignalMessage is the negative of the same parameter in SendSignalMessage. You see this in the line
Call( "SendSignalMessage", message, parameter, -direction, 1, linkIndex )
that is used to send a message into the same direction in which it was sent originally. Note the - that is needed to do so.
If you send a message into direction -1 (that is the direction of the black arrow in your drawing), then OnSignalMessage will receive a message from direction 1. This sounds stupid (and I think it is). The idea is that 1 is "forward" and -1 is "backward" and in OnSignalMessage 1 is interpreted as "from forward" and -1 is interpreted as "from backward" which is the exact opposite.
I hope that helped.
- dewilkinson
- Been on the forums for a while
- Posts: 198
- Joined: Sun Oct 13, 2013 7:44 pm
- Location: Northamptonshire, England
Re: How to debug signal ?
Just being simplistic, I was just wondering if you have the signal link to the track in the wrong place and it is detecting your train before you pass the signal. I always make sure there is a break in the track just before the track link which is placed after the signal, as I experienced a few difficulties to begin with and this 'cured' them. I attach an image of my typical signal set up.
Apologies if I have mis-understood your problem.
Apologies if I have mis-understood your problem.
David Wilkinson
Creating the Nene Valley Line
Creating the Nene Valley Line
Re: How to debug signal ?
Hi there
After a month work ,I have found the reason why the signal is blocked when the train stops. It is not the problem of the control signals ,but the script written in the auto signal is wrong. signal prepared was written to signal unprepared.
But now here is another problem.the code is like below(it is a control signal and it should be initialised to blocked)
first is the initialise function
then the signal message
The code I dont understand is when the scenario begin,it will pass the RESET_SIGNAL_STATE,the it will run the function of initialise()
All of the ctrl signals are set to Blocked .
But why there is a message = INITIALISE_SIGNAL_TO_BLOCKED and why the gOccupied [0] = gOccupied[0]+ 1 and gOccupied[linkIndex] = gOccupied[linkIndex] + 1
why the linkIndex receives messages will cause gOccupied [linkIndex]+ 1,and also gOccuped[0]?
I think there is no need to do this.
could someone please explain this usage ? thanks
After a month work ,I have found the reason why the signal is blocked when the train stops. It is not the problem of the control signals ,but the script written in the auto signal is wrong. signal prepared was written to signal unprepared.
But now here is another problem.the code is like below(it is a control signal and it should be initialised to blocked)
first is the initialise function
Code: Select all
function Initialise()
...
...
SetAspects( STOP )
Call ("Set2DMapSignalState", ANIMSTATE_RED)
...
end
Code: Select all
function OnSignalMessage( message, parameter, direction, linkIndex )
if message == RESET_SIGNAL_STATE then
Initialise()
elseif message == INITIALISE_SIGNAL_TO_BLOCKED then
if parameter == "DoNotForward" then
gInitStraddleLink[linkIndex] = TRUE
end
if linkIndex == 0 then
if parameter ~= "PassBack" then
gOccupied[0] = gOccupied[0] + 1
end
else
if gLinkSpeed[linkIndex] ~= 15 then -- Don't set occupation if this link is a yard.
gOccupied[linkIndex] = gOccupied[linkIndex] + 1
end
-- Pass back blocked message if it is received on link n, in case there are other signals spanning junction.
-- Use parameter to make sure link 0 ignores it.
if parameter ~= "DoNotForward" then
Call( "SendSignalMessage", INITIALISE_SIGNAL_TO_BLOCKED, "PassBack", REAR, 1, linkIndex )
end
...................
end
All of the ctrl signals are set to Blocked .
But why there is a message = INITIALISE_SIGNAL_TO_BLOCKED and why the gOccupied [0] = gOccupied[0]+ 1 and gOccupied[linkIndex] = gOccupied[linkIndex] + 1
why the linkIndex receives messages will cause gOccupied [linkIndex]+ 1,and also gOccuped[0]?
I think there is no need to do this.
could someone please explain this usage ? thanks
- AndiS
- Very Active Forum Member
- Posts: 6158
- Joined: Fri Sep 23, 2005 4:43 pm
- Location: Jester's cell in ivory tower
- Contact:
Re: How to debug signal ?
See here for a long write-up on this question.
In short:
Initialise is called very early by the system, when the track network is not yet set up.
Message RESET_SIGNAL_STATE is sent by the system on start-up and when you return from the editor.
Message INITIALISE_SIGNAL_TO_BLOCKED is sent when there is a train between this signal and the next signal. So you must do the same thing as if a train is passing. If the parameter is DoNotForward, then the train sits right on the link. What you do in this case depends on how you implement that tracking of trains. gOccupied[0] is traditionally used to count trains between link 0 and the other links.
In your case, you have four cases for this message:
Received on link 0 and not passed on by another link of the same signal: increment counter 0.
Received on link 0 and passed on by another link: Do nothing. Passing on is not useless as other signals want to know about this message, too. But when you reach link 0 of the first signal, passing on must stop.
Other link than 0 and it is a yard link: Do nothing because for yard links, occupation is not monitored.
Other link and not a yard link: Increment counter for that link.
In short:
Initialise is called very early by the system, when the track network is not yet set up.
Message RESET_SIGNAL_STATE is sent by the system on start-up and when you return from the editor.
Message INITIALISE_SIGNAL_TO_BLOCKED is sent when there is a train between this signal and the next signal. So you must do the same thing as if a train is passing. If the parameter is DoNotForward, then the train sits right on the link. What you do in this case depends on how you implement that tracking of trains. gOccupied[0] is traditionally used to count trains between link 0 and the other links.
In your case, you have four cases for this message:
Received on link 0 and not passed on by another link of the same signal: increment counter 0.
Received on link 0 and passed on by another link: Do nothing. Passing on is not useless as other signals want to know about this message, too. But when you reach link 0 of the first signal, passing on must stop.
Other link than 0 and it is a yard link: Do nothing because for yard links, occupation is not monitored.
Other link and not a yard link: Increment counter for that link.
Re: How to debug signal ?
Hi Andy
Thanks very much. I think I understand these codes.
I will try these code in my route to see the effects.
Thanks very much. I think I understand these codes.
I will try these code in my route to see the effects.