Know next signal aspect

robbys523252

New member
How can I know the status (getSignalState) of the next signal downstream of my section?
the method "AspectNextSignal = myGST.GetSignalState();" it gives me an error "function GetSignalState not declared in class GSTrackSearch
Thanks, Robert
 
How can I know the status (getSignalState) of the next signal downstream of my section?
the method "AspectNextSignal = myGST.GetSignalState();" it gives me an error "function GetSignalState not declared in class GSTrackSearch
Thanks, Robert

That error usually means that your calling parameters are not correct (usually the wrong type). Coding issues might go better in the scripting forum.

It often helps if you include some of your code.
 
Last edited:
You need to do something like:

Code:
MapObject nextMapObject;
GSTrackSearch myGST = me.BeginTrackSearch(true);


while(nextMapObject = myGST.SearchNext())
{
	if (cast<Signal> nextMapObject)
	{
		AspectNextSignal = (cast<Signal> nextMapObject).GetSignalStateEx();
		break;
	}
}
 
Thank you very much for your kindness Norfolksouthern37, but is it possible to know the appearance of the next signal as well (ie two signals after the one at the beginning)?
thanks and regards, Roberto ;)
 
Thank you very much for your kindness Norfolksouthern37, but is it possible to know the appearance of the next signal as well (ie two signals after the one at the beginning)?
thanks and regards, Roberto ;)

The tracksearch will continue to find objects until you either break out of it, or it runs out of objects to find. So yes, you can potentially ID the next n signals.
 
Hi, I need to know what the first two signals look like in front of me and the distance of these two signals from the starting point.
With this code that was kindly passed to me:


MapObject nextMapObject;
GSTrackSearch myGST = me.BeginTrackSearch(true);
while(nextMapObject = myGST.SearchNext())
{
if (cast<Signal> nextMapObject)
{
AspectNextSignal = (cast<Signal> nextMapObject).GetSignalStateEx();
breaks;
}
}
I can detect its appearance and with this other code:
GSTrackSearch myGST = me.BeginTrackSearch(true);
MapObject nextMapObject = myGST.SearchNext();
cast<Signal>nextMapObject;
NextSignalDistance = myGST.GetDistance();
I can know the distance, but only of the next signal, not the next one yet.
I hope I expressed myself well and thanks for any help.
Greetings
 
You should read the description of how the class GSTrackSearch works. It will continue searching until you break out of it, or it has no more track to search. A couple of other special cases that you can read about. So just check each object found for signals.
 
I've created these functions which will return the speed or aspect of the n'th signal in either direction from the advanced signal states (https://online.ts2009.com/mediaWiki/index.php/Class_Signal#Extended_Signal_States).

The functions you actually call are GetSpeedLimit or GetSignalAspectEx. The other two are functions that they each need. For GetSignalAspectEx, the "dir" bool variable is which direction (relative to the signal and track) to search. The "indx" integer variable is which one to look for in that direction. For example GetSignalAspectEx(true, 0) will return the aspect of the first (next) signal in front of this signal. GetSignalAspectEx(true, 1) will return the aspect of the one after the next one (the second after this one), GetSignalAspectEx(true, 2) will return the 3rd, and so on. GetSignalAspectEx(false, 0) will return the one before this one. If nothing is found at that index, it will return -1. The same applies to the GetSpeedLimit, except it will return a floating point number for the speed (in Meters Per Second), and look only for speedboards. When searching, both functions will ignore trackside objects that are not of the respective type, so it will always find the n'th signal, even if there are other trackside objects (like speedboards) between them.

Code:
float GetSpeedLimit(bool dir, int indx)
{
    if (BeginTrackSearch(dir))
    {
        GSTrackSearch SearchDirection = BeginTrackSearch(dir);
        Trackside TargetTrackside = GetTrackSideSpeedLimit(SearchDirection, indx);
        if (TargetTrackside)
        {
            if (TargetTrackside.GetSpeedLimit())
            {
                return TargetTrackside.GetSpeedLimit();
            }
        }
    }
    //Nothing found
    return -1.0;
}



int GetSignalAspectEx(bool dir, int indx)
{
    if (BeginTrackSearch(dir))
    {
        GSTrackSearch SearchDirection = BeginTrackSearch(dir);
        Trackside TargetTrackside = GetTrackSideSignal(SearchDirection, indx);
        if (TargetTrackside)
        {
            if (TargetTrackside != null)
            {
                return TargetTrackside.GetSignalStateEx();
            }
        }
    }
    //Nothing found
    return -1;
}



Trackside GetTrackSideSignal(GSTrackSearch SpeedObj, int index)
{
    Trackside foundTrackside;
    while (SpeedObj.SearchNextObject())
    {
        foundTrackside = cast < Signal > SpeedObj.GetObject();
        if (foundTrackside != null)
        {
            if (index == 0)
            {
                return foundTrackside;
            }
            else
            {
                index = index - 1;
            }
        }
    }
    //Nothing found
    return null;
}



Trackside GetTrackSideSpeedLimit(GSTrackSearch SpeedObj, int index)
{
    Trackside foundTrackside;
    while (SpeedObj.SearchNextObject())
    {
        foundTrackside = cast < Trackside > SpeedObj.GetObject();
        if ((int)foundTrackside.GetSpeedLimit() != 0)
        {
            if (index == 0)
            {
                return foundTrackside;
            }
            else
            {
                index = index - 1;
            }
        }
    }
    //Nothing found
    return null;
}
 
Last edited:
Dundun92, thank you so much, it was what I needed and you described it very clearly!
Thanks again and greetings, Roberto :Y:
 
Last edited:
Hello, thanking again those who helped me with some examples, I ask for clarification: how can I prevent the search for the next signal from stopping on a signal placed in the opposite direction (but on the same track) to the desired one?
Using:
MapObject nextMapObject;
GSTrackSearch myGST = me.BeginTrackSearch(true);
while(nextMapObject = myGST.SearchNext())
{
if (cast<Signal> nextMapObject)
{
AspectNextSignal = (cast<Signal> nextMapObject).GetSignalStateEx();
breaks;
}
}
it detects the appearance, yes, of the next signal, but even if this signal is placed in the opposite direction and I would like this not to happen.
Thanks again for any help, greetings Roberto
 
Last edited:
Hello, thanking again those who helped me with some examples, I ask for clarification: how can I prevent the search for the next signal from stopping on a signal placed in the opposite direction (but on the same track) to the desired one?
Using:
MapObject nextMapObject;
GSTrackSearch myGST = me.BeginTrackSearch(true);
while(nextMapObject = myGST.SearchNext())
{
if (cast<Signal> nextMapObject)
{
AspectNextSignal = (cast<Signal> nextMapObject).GetSignalStateEx();
breaks;
}
}
it detects the appearance, yes, of the next signal, but even if this signal is placed in the opposite direction and I would like this not to happen.
Thanks again for any help, greetings Roberto

use:

myGST.GetFacingRelativeToSearchDirection()

This is a bool that will tell if the object is the right way or not.
 
Back
Top