How to search objects on a huge routes

BUGOR

New member
Hello! I have some problems in TRS19 with searching of GameObjects.
Primary, I want to show you what I have in a code:

1.
Code:
    public NamedObjectInfo[] SynchronouslyGetNamedObjectList(string categoryFilter, string zhel1)     { 
    AsyncObjectSearchResult asyncSearch = World.GetNamedObjectList(categoryFilter, zhel1); 
    Sniff(asyncSearch, "ObjectSearch", "AsyncResult", true); 
    Message msg; 


    wait() 
    { 
    on "ObjectSearch", "AsyncResult", msg: 
    if (msg.src == asyncSearch) 
    break; 
    continue; 
    }; 


    int errCode = asyncSearch.GetSearchErrorCode(); 
    if (errCode != AsyncObjectSearchResult.ERROR_NONE) 
    Interface.Print("RDSjunction.SynchronouslyGetNamedObjectList> Search failed, error: " + errCode); 


    return asyncSearch.GetResults(); 
    }

2.
Code:
Signal FindSignalByName (string SignalName)    {
        
        int i;
        for (i = 0; i < allSgn.size (); i++)
        {
            if (allSgn[i].localisedUsername == SignalName) 
            return cast<Signal>allSgn[i].objectRef;
        }
        return null;
    }

Of course I have declaration of variable allSgn and in a function meaning of its:
Code:
allSgn = SynchronouslyGetNamedObjectList(AssetCategory.Signal, "");

And variables take on meanings like this:
Code:
sign_n = FindSignalByName ("zhel_n");
For sure variables like this is a "Signal" kind.

The things I need to do:
1. Seeking of a lot of signals and junctions on a huge route.
2. Changing variables inside these signals.
3. Changing directions of junctions.
4. And these all are for interlocking of the route. I need to do my own, because there is an especial interlocking systems in Russia. It's not universal, just for my own route and because of this I have to find all necessary junctions and signals by its names, because it will not change ever.

Circumstances I have:
1. For sure code is correct, because on a small test route it's completely workable.
2. On a huge route there is an error: NULL_reference while I am trying to change something inside these variables.
3. The main thing! The error NULL_reference is not every time, it's 50% only. One time it works, another is not.

This is a mini-map of my route for now(it will rise):



Is there something I have to do for making this search correct in 100%?
 
Last edited:
I don't need to seek in manually. I need to seek it from script and for script needs. It should be automatically. However, now I am trying to use old Router.GetGameObject() and it unprecedented works, but new Async search doesn't work at all, especially in driver mode.
 
Hi.

Two questions :

1 - does your SynchronouslyGetNamedObjectList(...) is executed under a thread ? You need to execute the code under a thread to be able to wait for the results.

2 - Does your performance option is set to « maximize compatibility » mode or is it set to « stream objects ». With stream objects, you cannot assume that all objects are loaded : and allSgn.objectRef may be null for a not loaded object. In this case, you need to add the instructions to request to load the object if you need to access its properties.

All my scripts have been fully migrated to the new async searches, and it works perfectly with no errors and no failure ...

regards.
Pierre.
 
1. How to do it? I'm not sure about it. All that concerns code is in my post there.

2. It's on "maximize compatibility".

The main question: is it workable on a really huge routes? If it's not everything new inside TRS19 becomes useless.
 
pguy, tell more about this case: "in this case, you need to add the instructions to request to load the object if you need to access its properties."

What should I exactly do to make this instructions? And what kind of instructions you are talking about?
 
Hi.

I would add two code sequences inside your SynchronouslyGetNamedObjectList function :

- first one to be added at the beginning of your function is a sequence of code to check that your are called under a thread, firing an exception if it is not the case. This may help to diagnose situations with invalid context call.

GameObject callingThread = Router.GetCurrentThreadGameObject() ;
if (!callingThread)
{
// error - function has been called not under a thread
Interface.Exception(« ERROR - SynchronouslyGetNamedObjectList has been called not under a thread ... ») ;
return ;
}

- second one is a modified sequence to try to load the object reference from its gameobjectid if it is not currently loaded (should only happen with thread objects option active) :

. . .
if (allSgn.localisedUsername == signalName)
{
Signal signal = cast<Signal> allSgn.objectRef ;
if (!signal)
// try retrieving object from its gameobject if already loaded
signal = cast<Signal> World.GetGameObjectByIDIfLoaded(allSgn.objectId) ;
if (!signal)
// try loading and retrieving object from its gameobject if not loaded (works only under a thread ...)
signal = caste <Signal> World.SynchronouslyLoadGameObjectByID(allSgn.objectId) ;
return signal ;
}
. . .

Hope this may help. Regards.
Pierre.
 
I found that array AsyncObjectSearchResult has a limit of 1000 cells, which is why some of the objects are simply not located on a large route. :(
 
"Making of a Russian real route. One day I will create a thread here." Curious, does anyone know if there was a thread for this route, or which route it was/is?
 
Back
Top