Need help in scripting about World.GetNamedObjectList()

ARgrigorov

New member
I need to get a list of all tracks in the session for handling message Train,EnterTrack.

I use this code for get the tracks list:
Code:
		AsyncObjectSearchResult asyncSearch;
		asyncSearch = World.GetNamedObjectList(AssetCategory.Track, "");
		if(asyncSearch.SynchronouslyWaitForResults("AsyncResult")){
			NamedObjectInfo[] results = asyncSearch.GetResults();
			int results_size = results.size();
			int i;
			for(i = 0; i < results_size; i++){
				Sniff(results[i].objectId, "Train", "EnterTrack", true);
			}
		}
but after search results_size == 0.
What am I doing wrong?
 
hi, ARgrigorov, there is a special section in the forum for script help


Your code syntax seems correct
You use that new search method, and somehow whatever I do with it fails
beside it being too complex it just does not give me stable (=all)results
you use GetNamedObjectList, but does a track segment actualy have a name?, it will have an ID ofc.


Often in trainz script(and life) there are more ways to reach the same goal
Can you describe what the actual goal is?
Can the same be done via a GStracksearch, from the train?
lets say you want to know if a train is between junction 1 and junction 2
then you can do a track search and check the results
greetings GM
 
there is a special section in the forum for script help
Please indicate me - in which section of the forum it is better to create posts with questions about scripting? (I didn't find this section).

Can you describe what the actual goal is?
I'm working on an extension the functionality of the Su signalisation.
My goal is to handle a train spawning in session by user or portal.
I didn't find in wiki information about broadcast message like Train,Spawn or Train,Create (just found only Train,Cleanup and Train,Delete).
And I decided to handle the message Track,Enter for determine train spawning in session. For this I need a list of all tracks in session for call Sniff(founded_track, "Track", "Enter", true).
If it possible to realise this by other more simple way, I will be grateful to you, if you point this out to me.
 
Last edited:
Can the same be done via a GStracksearch, from the train?
After thinking about it a little more, I realized that, theoretically, it is possible to implement this task using GSTrackSearch - find the signals with World.GetNamedObjectList(), and run GSTrackSearch from them to find tracks on which we need to install the event handler Train,EnterTrack, but this method seems to me too slow.
 
Last edited:
the part of the forum for script help is here
https://forums.auran.com/trainz/forumdisplay.php?23-Scenario-Scripting-amp-Scriptlets


So the goal is:
-know that a train is new/generated in the session
-where is it new/generated?
-then adjust your signals?


A few messages you can search for that are broadcasted:
-DriverCharacter,BoardedTrain
if a train is placed/spawned it needs a driver right?
-Vehicle,Coupled
this gets send a lot when new trains appear/are altered
-Schedule,Complete
Sent when a command schedule is completed
-maybe also Industry messages, cause a portal is an Industry i think


things to study:
kuid 121843 100602 InstantMoveTrain
excellent rule by Pitkin that moves a complete train
and the various portals built-in by Auran
greetings GM
 
For an example of GSTrackSearch, examine my Junction Derailment Prevention. The user interface was broken years ago, but the internal mechanisms still function. (For anyone interested, the rule still works, you just can't change some of the functions in the UI).
 
Back
Top