<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.trainzsimulator.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fwassner</id>
	<title>TrainzOnline - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.trainzsimulator.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fwassner"/>
	<link rel="alternate" type="text/html" href="https://wiki.trainzsimulator.com/wiki/Special:Contributions/Fwassner"/>
	<updated>2026-11-05T06:38:01Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://wiki.trainzsimulator.com/index.php?title=Class_GSTrackSearch&amp;diff=1468</id>
		<title>Class GSTrackSearch</title>
		<link rel="alternate" type="text/html" href="https://wiki.trainzsimulator.com/index.php?title=Class_GSTrackSearch&amp;diff=1468"/>
		<updated>2010-08-22T16:42:20Z</updated>

		<summary type="html">&lt;p&gt;Fwassner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[TrainzScript Language Reference|API Hierarchy]]&lt;br /&gt;
**GSTrackSearch&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*A class enabling the searching of a length of track for [[class Trackside|Trackside]] items. &lt;br /&gt;
*The GSTrackSearch class provides an interface to access certain items along a track in a specified direction from an existing trackside item. &lt;br /&gt;
*A GSTrackSearch object can be obtained by calling the [[Class Trackside#BeginTrackSearch|BeginTrackSearch()]] method on the [[class Trackside|Trackside]] item that you want to start your search from. &lt;br /&gt;
*The SearchNext() and GetMapObject() methods are provided to get a reference to a discovered [[class Trackside|Trackside]] object.&lt;br /&gt;
*The reference returned by these methods can be cast to [[class Trackside|Trackside]] child classes to find out if that item is in fact a [[class Signal|Signal]] or a [[class Junction|Junction]] for instance. As the script code doesn&#039;t know what the next item will be, always verify the cast. &lt;br /&gt;
*Since [[class Vehicle|Vehicles]] and [[Class Locomotive|Locomotives]] descend from [[class Trackside|Trackside]], searches can be initiated from rolling stock and rolling stock will be returned.&lt;br /&gt;
*GSTrackSearch methods will also find [[Class SceneryWithTrack|SceneryWithTrack]] and descendants, although the information which can be obtained from them is limited and these objects cannot be used to initiate a search.&lt;br /&gt;
*The search will continue (following the direction set by any junctions) until it is blocked by:&lt;br /&gt;
**A junction set against the track&lt;br /&gt;
**A turntable.&lt;br /&gt;
**A crossing. *** ? &amp;quot;crossing&amp;quot; appears to mean a track (diamond, etc), rather than a road (grade, level) crossing, since the function appears to work properly across road crossings. &lt;br /&gt;
**The end of the line.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*See [[TrackSearch]] for details of enhancements being developed for future versions of the game.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Trackside.BeginTrackSearch==&lt;br /&gt;
{{MethodHeader|public native GSTrackSearch Trackside.BeginTrackSearch(bool direction)}}&lt;br /&gt;
*This method is called on objects descending from the [[class Trackside|Trackside]] class to obtain a GSTrackSearch object in the specified search direction.&lt;br /&gt;
*See [[Class Trackside#BeginTrackSearch|Trackside.BeginTrackSearch()]] for details.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==GetDistance==&lt;br /&gt;
{{MethodHeader|public native float GetDistance(void)}}&lt;br /&gt;
;Parameters&lt;br /&gt;
*None&lt;br /&gt;
;Returned Value&lt;br /&gt;
*The distance in metres from the origin of the search to the object at which the search cursor is currently pointing.&lt;br /&gt;
;Syntax&lt;br /&gt;
 float distance = gst.GetDistance();&lt;br /&gt;
;Notes&lt;br /&gt;
*See [[#Code Examples|Code Examples]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==GetFacingRelativeToSearchDirection==&lt;br /&gt;
{{MethodHeader|public native bool GetFacingRelativeToSearchDirection(void)}}&lt;br /&gt;
;Parameters&lt;br /&gt;
*None&lt;br /&gt;
;Returned Value&lt;br /&gt;
*True if the returned object orientation matches the direction of search, false otherwise.&lt;br /&gt;
;Syntax&lt;br /&gt;
 bool facing = gst.GetFacingRelativeToSearchDirection();&lt;br /&gt;
;Notes&lt;br /&gt;
*Note that it is the direction of the search that matters, not the facing direction of the search origin.&lt;br /&gt;
*A search forwards from a fixed object such as a [[Class Trigger|Trigger]] will return &#039;&#039;&#039;true&#039;&#039;&#039; for any returned trigger which has the same orientation as the source. &lt;br /&gt;
*A search backwards from a fixed object such as a [[Class Trigger|Trigger]] will return &#039;&#039;&#039;false&#039;&#039;&#039; for any returned trigger which has the same orientation as the source. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==GetMapObject==&lt;br /&gt;
{{MethodHeader|public native MapObject GetMapObject(void)}}&lt;br /&gt;
;Parameters&lt;br /&gt;
*None&lt;br /&gt;
;Returned Value&lt;br /&gt;
*A reference to a MapObject or null if nothing has been found.&lt;br /&gt;
;Syntax&lt;br /&gt;
 MapObject mo = gst.GetMapObject();&lt;br /&gt;
;Notes&lt;br /&gt;
*MapObject returns Trackside descendants including Vehicles and SceneryWithTrack descendants including Industries.&lt;br /&gt;
*Ensure that you attempt a cast to SceneryWithTrack and Trackside if you want the maximum possible amount of information from the search.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SearchNext==&lt;br /&gt;
{{MethodHeader|public native MapObject SearchNext(void)}}&lt;br /&gt;
;Parameters&lt;br /&gt;
*None&lt;br /&gt;
;Returned Value&lt;br /&gt;
*A reference to a MapObject or null if nothing has been found.&lt;br /&gt;
;Syntax&lt;br /&gt;
 MapObject mo = gst.GetMapObject();&lt;br /&gt;
;Notes&lt;br /&gt;
*SearchNext moves the search cursor to the next object if such an object exists.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Known Issues==&lt;br /&gt;
*GSTrackSearch will return a null reference if it finds certain types of [[Class Crossing|Crossing]] objects, but will continue searching beyond them if asked.  As a result of this it is often necessary to make repeated calls to SearchNext following a null return to decide whether you have reached the end of the track or whether your search has simply been interrupted by one or more crossings.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Code Examples==&lt;br /&gt;
*This code fragment implements a search forwards from a locomotive. The distance from the locomotive to any discovered object is printed to &#039;&#039;jetlog.txt&#039;&#039;&lt;br /&gt;
*The process continues until the search returns a null value (which might be a crossing or the end of the track) or the distance from the train exceeds 1km.&lt;br /&gt;
 GSTrackSearch gst = Loco.BeginTrackSearch(true);          // obtain a GSTrackSearch object&lt;br /&gt;
 MapObject mo = gst.SearchNext();                          // initiate the search&lt;br /&gt;
 while (mo) {                                              // continue as long as objects are present&lt;br /&gt;
   float distance = mo.GetDistance();                      // how far ahead the object is&lt;br /&gt;
   if (distance() &amp;gt; 1000.0) break;                         // break from the loop if the distance exceeds 1km&lt;br /&gt;
   Interface.Print(&amp;quot;object found at &amp;quot; distance &amp;quot; metres&amp;quot;); // print out the results&lt;br /&gt;
   mo = gst.SearchNext();                                  // search for the next object&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Related Methods==&lt;br /&gt;
[[Class Trackside#BeginTrackSearch|Trackside.BeginTrackSearch()]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Categories==&lt;br /&gt;
[[Category:Script Class]]&lt;/div&gt;</summary>
		<author><name>Fwassner</name></author>
	</entry>
</feed>