Class World

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
(Play2DSound)
(GetNamedObjectList)
 
(21 intermediate revisions by 9 users not shown)
Line 1: Line 1:
*[[TrainzScript Language Reference|API Hierarchy]]
+
*[[TrainzScript Library Reference|API Hierarchy]]
**World
+
**World (world.gs)
 
<br>
 
<br>
 
*World is a static class used to access various aspects of the Trainz environment.
 
*World is a static class used to access various aspects of the Trainz environment.
Line 13: Line 13:
 
===Camera View Modes===
 
===Camera View Modes===
 
----
 
----
*These values can be used either to choose the current camera viewing mode through World.SetCameraMode(), or to restrict certain camera modes from being accessed through methods such as World.SetCamera().
+
*These values can be used either to choose the current camera viewing mode through World.[[#SetCameraMode|SetCameraMode()]], or to restrict certain camera modes from being accessed through methods such as World.[[#SetCamera|SetCamera()]].
  
 
{{TableHeader|width=95%|margin=15px}}
 
{{TableHeader|width=95%|margin=15px}}
Line 47: Line 47:
 
----
 
----
 
*Define the current state of the weather in Trainz.  
 
*Define the current state of the weather in Trainz.  
*A variety of weather conditions are supported and can be changed by using one of these values with the World.SetWeather() method.  
+
*A variety of weather conditions are supported and can be changed by using one of these values with the World.[[#SetWeather|SetWeather()]] method.  
 
{{TableHeader|width=95%|margin=15px}}
 
{{TableHeader|width=95%|margin=15px}}
 
|width=375|public define int WEATHER_TYPE_CLEAR = 0||Clear weather, no clouds, rain or snow.
 
|width=375|public define int WEATHER_TYPE_CLEAR = 0||Clear weather, no clouds, rain or snow.
Line 97: Line 97:
 
----
 
----
 
*Values that define the time rates relative to normal time.  
 
*Values that define the time rates relative to normal time.  
*These constants can be used to set the time rate that Trainz runs out through the World.SetGameTimeRate() method.  
+
*These constants can be used to set the time rate that Trainz runs out through the World.[[#SetGameTimeRate|SetGameTimeRate()]] method.  
 
{{TableHeader|width=95%|margin=15px}}
 
{{TableHeader|width=95%|margin=15px}}
 
|width=375|public define int  TIME_RATE_1X = 0||Real time (i.e. time in Trainz passes at the same rate as in the real world)
 
|width=375|public define int  TIME_RATE_1X = 0||Real time (i.e. time in Trainz passes at the same rate as in the real world)
Line 113: Line 113:
 
|public define int TIME_RATE_60X = 6||
 
|public define int TIME_RATE_60X = 6||
 
|-
 
|-
| public define int TIME_RATE_120X = 7||
+
|public define int TIME_RATE_120X = 7||
 
|-
 
|-
| public define int TIME_RATE_240X = 8||
+
|public define int TIME_RATE_240X = 8||
 
|-
 
|-
 
|public define int TIME_RATE_360X = 9||
 
|public define int TIME_RATE_360X = 9||
Line 128: Line 128:
 
|-
 
|-
 
|public define int TIME_RATE_1440X = 14||
 
|public define int TIME_RATE_1440X = 14||
 +
|}
 +
<br>
 +
 +
===Layer Type Constants===
 +
----
 +
*These constants can be used for querying route/session layers via [[#GetLayerList|GetLayerList]] and [[#GetLayerType|GetLayerType]].
 +
*<font color=red>Added in TRS19?</font>
 +
{{TableHeader|width=95%|margin=15px}}
 +
|width=375|public define int LAYER_INVALID = 0||
 +
|-
 +
|public define int LAYER_ROUTE = 1||
 +
|-
 +
|public define int LAYER_SESSION = 2||
 +
|-
 +
|public define int LAYER_BOTH = 3||
 +
|}
 +
<br>
 +
 +
===World Editing Mode Constants===
 +
----
 +
*These constants can be used to set editing modes through World.[[#SetWorldEditModeEnabled|SetWorldEditModeEnabled()]].
 +
*<font color=red>Added in TRS19?</font>
 +
{{TableHeader|width=95%|margin=15px}}
 +
|width=375|public define int PERMIT_EDIT_NONE = 0x0||
 +
|-
 +
|public define int PERMIT_EDIT_TOPOLOGY = 0x1||
 +
|-
 +
|public define int PERMIT_EDIT_PAINT = 0x2||
 +
|-
 +
|public define int PERMIT_EDIT_SCENERYOBJECTS = 0x4||
 +
|-
 +
|public define int PERMIT_EDIT_SCENERYSPLINES = 0x8||
 +
|-
 +
|public define int PERMIT_EDIT_TRACKSPLINES = 0x10||
 +
|-
 +
|public define int PERMIT_EDIT_TRACKSIDEOBJECTS = 0x20||
 +
|-
 +
|public define int PERMIT_EDIT_TRACKMARKS = 0x40||
 +
|-
 +
|public define int PERMIT_EDIT_TOOLS = 0x80||
 +
|-
 +
|public define int PERMIT_EDIT_WORLD = 0x100||
 +
|-
 +
|public define int PERMIT_EDIT_LAYERS = 0x200||
 +
|-
 +
|public define int PERMIT_EDIT_TRAINS = 0x400||
 +
|-
 +
|public define int PERMIT_EDIT_CONSISTS = 0x800||
 +
|-
 +
|public define int PERMIT_EDIT_ALL = -1||
 
|}
 
|}
 
<br>
 
<br>
Line 152: Line 202:
  
 
==AddDriverCharacter==
 
==AddDriverCharacter==
{{MethodHeader|public native DriverCharacter AddDriverCharacter(Asset driverCharacterAsset)}}
+
{{MethodHeader|public native [[Class DriverCharacter|DriverCharacter]] AddDriverCharacter([[Class Asset|Asset]] driverCharacterAsset)}}
 
;Parameters
 
;Parameters
 
*'''driverCharacterAsset''' = Asset containing character to be added.
 
*'''driverCharacterAsset''' = Asset containing character to be added.
Line 160: Line 210:
 
  DriverCharacter Casey = World.AddDriverCharacter(CaseyJones);
 
  DriverCharacter Casey = World.AddDriverCharacter(CaseyJones);
 
;Notes
 
;Notes
 +
*In multiplayer, this will only succeed on the server.
 
<br>
 
<br>
  
 
==AddDriverCommand==
 
==AddDriverCommand==
{{MethodHeader|public native DriverCommand AddDriverCommand(Asset driverCommandAsset)}}
+
{{MethodHeader|public native [[Class DriverCommand|DriverCommand]] AddDriverCommand([[Class Asset|Asset]] driverCommandAsset)}}
 
;Parameters
 
;Parameters
 
*'''driverCommandAsset''' = Asset containing command to be added.
 
*'''driverCommandAsset''' = Asset containing command to be added.
Line 171: Line 222:
 
  DriverCommand GoFaster = World.AddDriverCommand(accelerate);
 
  DriverCommand GoFaster = World.AddDriverCommand(accelerate);
 
;Notes
 
;Notes
 +
*In multiplayer, this will only succeed on the server.
 +
<br>
 +
 +
==CancelCurrentEditingMode==
 +
{{MethodHeader|public native void CancelCurrentEditingMode(void)}}
 +
;Parameters
 +
*None
 +
;Returned Value
 +
*None
 +
;Syntax
 +
World.CancelCurrentEditingMode();
 +
;Notes
 +
* Cancels out of any player entered editing mode, if relevant. This should only normally be called as a result of direct player action.
 +
*<font color=red>Added in TRS19?</font>
 
<br>
 
<br>
  
 
==CreateBehavior==
 
==CreateBehavior==
{{MethodHeader|public native ScenarioBehavior CreateBehavior(KUID kuid, Soup initialProperties)}}
+
{{MethodHeader|public native [[Class ScenarioBehavior|ScenarioBehavior]] CreateBehavior([[Class KUID|KUID]] kuid, [[Class Soup|Soup]] initialProperties)}}
 
;Parameters
 
;Parameters
 
*'''kuid''' = KUID of scenario.
 
*'''kuid''' = KUID of scenario.
Line 187: Line 252:
  
 
==CreateTrain==
 
==CreateTrain==
{{MethodHeader|public native Train CreateTrain(KUID[ ] consist, string trackmarkName, bool direction)<br>public native Train CreateTrain(KUID[ ] consist, TrackMark trackmark, bool direction)<br>public native Train CreateTrain(KUID[ ] consist, Buildable buildable, string trackName, float position, bool direction)}}
+
{{MethodHeader|public native [[Class Train|Train]] CreateTrain([[Class KUID|KUID]][ ] consist, string trackmarkName, bool direction)<br>public native [[Class Train|Train]] CreateTrain([[Class KUID|KUID]][ ] consist, [[Class TrackMark|TrackMark]] trackmark, bool direction)<br>public native [[Class Train|Train]] CreateTrain([[Class KUID|KUID]][ ] consist, [[Class Buildable|Buildable]] buildable, string trackName, float position, bool direction)<br>public native [[Class Train|Train]] CreateTrain([[Class KUID|KUID]][ ] consist, [[Class GSTrackSearch|GSTrackSearch]] tracksearch, bool avoidDerailments)<br>public native [[Class Train|Train]] CreateTrain([[Class KUID|KUID]][ ] consist, [[Class GSTrackSearch|GSTrackSearch]] tracksearch)}}
 
;Parameters
 
;Parameters
 
*'''consist''' = An array of vehicle KUIDs used to describe the required Train object.
 
*'''consist''' = An array of vehicle KUIDs used to describe the required Train object.
Line 196: Line 261:
 
*'''trackmark''' = Reference to Trackmark at which the consist is to be formed.
 
*'''trackmark''' = Reference to Trackmark at which the consist is to be formed.
 
*'''direction''' = Orientation of Train relative to direction of track or trackmark.
 
*'''direction''' = Orientation of Train relative to direction of track or trackmark.
 +
*'''tracksearch''' = The location at which to create the train
 +
*'''avoidDerailments''' = If true this function will fail and return null if creating the train would cause a derailment
 
;Returned Value
 
;Returned Value
 
*Reference to the Train created if successful, null otherwise.
 
*Reference to the Train created if successful, null otherwise.
Line 204: Line 271:
 
*Depending on the variant of the method used, the train can be created at a Trackmark, specified by name or reference, or at a Buildable or Industry object.
 
*Depending on the variant of the method used, the train can be created at a Trackmark, specified by name or reference, or at a Buildable or Industry object.
 
*It is the responsibility of the script programmer to ensure that sufficient track exists at the given location to allow the train to be created.
 
*It is the responsibility of the script programmer to ensure that sufficient track exists at the given location to allow the train to be created.
 +
*In multiplayer, this will only succeed on the server.
 +
*<font color=red>'''GSTrackSearch''' aliases added in TRS19?</font>
 
<br>
 
<br>
  
 
==DeleteTrain==
 
==DeleteTrain==
{{MethodHeader|public native void DeleteTrain(Train train)}}
+
{{MethodHeader|public native void DeleteTrain([[Class Train|Train]] train)}}
 
;Parameters
 
;Parameters
 
*'''train''' = train to be deleted from map.
 
*'''train''' = train to be deleted from map.
Line 216: Line 285:
 
;Notes
 
;Notes
 
*Once a train has been deleted, care should be taken to avoid using its reference.
 
*Once a train has been deleted, care should be taken to avoid using its reference.
 +
*In multiplayer, this will only succeed on the server.
 
<br>
 
<br>
  
 
==DeleteVehicle==
 
==DeleteVehicle==
{{MethodHeader|public native void DeleteVehicle(Vehicle vehicle)}}
+
{{MethodHeader|public native void DeleteVehicle([[Class Vehicle|Vehicle]] vehicle)}}
 
;Parameters
 
;Parameters
 
*'''vehicle''' = vehicle to be deleted from its train.
 
*'''vehicle''' = vehicle to be deleted from its train.
Line 227: Line 297:
 
  World.DeleteVehicle(vehicles[vehicles.size()-1]);
 
  World.DeleteVehicle(vehicles[vehicles.size()-1]);
 
;Notes
 
;Notes
*Use Train.GetVehicles() to obtain an array of vehicles for a given train.
+
*Use [[Class Train#GetVehicles|Train.GetVehicles()]] to obtain an array of vehicles for a given train.
*Use Vehicle.GetMyTrain() to obtain a train reference for a given vehicle.
+
*Use [[Class Vehicle#GetMyTrain|Vehicle.GetMyTrain()]] to obtain a train reference for a given vehicle.
 +
*In multiplayer, this will only succeed on the server.
 +
<br>
 +
 
 +
==EndScenario==
 +
{{MethodHeader|public void EndScenario(float time)}}
 +
;Parameters
 +
*'''time''' = Amount of seconds to delay before ending the session
 +
;Returned Value
 +
*None
 +
;Syntax
 +
World.EndScenario(30.0);
 +
;Notes
 +
*In multiplayer, this will only succeed on the server.
 
<br>
 
<br>
  
 
==FindAsset==
 
==FindAsset==
{{MethodHeader|public native Asset FindAsset(KUID kuid)}}
+
{{MethodHeader|public native [[Class Asset|Asset]] FindAsset([[Class KUID|KUID]] kuid)}}
 
;Parameters
 
;Parameters
 
*'''kuid''' = KUID of Asset to return.
 
*'''kuid''' = KUID of Asset to return.
Line 244: Line 327:
  
 
==FindDriverCommand==
 
==FindDriverCommand==
{{MethodHeader|public native DriverCommand FindDriverCommand(Asset driverCommandAsset)}}
+
{{MethodHeader|public native [[Class DriverCommand|DriverCommand]] FindDriverCommand([[Class Asset|Asset]] driverCommandAsset)}}
 
;Parameters
 
;Parameters
 
*'''driverCommandAsset''' = Asset containing command to be added.
 
*'''driverCommandAsset''' = Asset containing command to be added.
Line 255: Line 338:
  
 
==GetAssetList==
 
==GetAssetList==
{{MethodHeader|public native Asset[ ] GetAssetList(string kind)}}
+
{{MethodHeader|public native [[Class Asset|Asset]][ ] GetAssetList(string kind)}}
 
;Parameters
 
;Parameters
 
*'''kind''' = String representing the Kind of asset to return.
 
*'''kind''' = String representing the Kind of asset to return.
Line 267: Line 350:
  
 
==GetBadWeatherFog==
 
==GetBadWeatherFog==
{{MethodHeader|public native float GetBadWeatherFog(void)}}
+
{{MethodHeader|public obsolete native float GetBadWeatherFog(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 275: Line 358:
 
  float dist = World.GetBadWeatherFog();
 
  float dist = World.GetBadWeatherFog();
 
;Notes
 
;Notes
 +
*Obsolete in TRS19
 
<br>
 
<br>
  
 
==GetBehaviors==
 
==GetBehaviors==
{{MethodHeader|public native ScenarioBehavior[ ] GetBehaviors(void)}}
+
{{MethodHeader|public native [[Class ScenarioBehavior|ScenarioBehavior]][ ] GetBehaviors(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 286: Line 370:
 
  ScenarioBehavior[] rules = World.GetBehaviors();
 
  ScenarioBehavior[] rules = World.GetBehaviors();
 
;Notes
 
;Notes
 +
<br>
 +
 +
==GetCameraPitch==
 +
{{MethodHeader|public native float GetCameraPitch(void)}}
 +
;Parameters
 +
*None
 +
;Returned Value
 +
*Current camera pitch, in radians
 +
;Syntax
 +
float pitch = World.GetCameraPitch();
 +
;Notes
 +
*<font color=red>Added in ...?</font>
 
<br>
 
<br>
  
 
==GetCameraPositionX==
 
==GetCameraPositionX==
{{MethodHeader|public native float GetCameraPositionX(void)}}
+
{{MethodHeader|public obsolete native float GetCameraPositionX(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 296: Line 392:
 
;Syntax
 
;Syntax
 
  float X = World.GetCameraPositionX();
 
  float X = World.GetCameraPositionX();
*Notes
+
;Notes
 +
*Obsolete in TRS19
 
<br>
 
<br>
  
 
==GetCameraPositionY==
 
==GetCameraPositionY==
{{MethodHeader|public native float GetCameraPositionY(void)}}
+
{{MethodHeader|public obsolete native float GetCameraPositionY(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 307: Line 404:
 
;Syntax
 
;Syntax
 
  float Y = World.GetCameraPositionY();
 
  float Y = World.GetCameraPositionY();
*Notes
+
;Notes
 +
*Obsolete in TRS19
 
<br>
 
<br>
  
 
==GetCameraPositionZ==
 
==GetCameraPositionZ==
{{MethodHeader|public native float GetCameraPositionZ(void)}}
+
{{MethodHeader|public obsolete native float GetCameraPositionZ(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 318: Line 416:
 
;Syntax
 
;Syntax
 
  float Z = World.GetCameraPositionZ();
 
  float Z = World.GetCameraPositionZ();
*Notes
+
;Notes
 +
*Obsolete in TRS19
 +
<br>
 +
 
 +
==GetCameraYaw==
 +
{{MethodHeader|public native float GetCameraYaw(void)}}
 +
;Parameters
 +
*None
 +
;Returned Value
 +
*Current camera yaw, in radians
 +
;Syntax
 +
float yaw = World.GetCameraYaw();
 +
;Notes
 +
*<font color=red>Added in ...?</font>
 +
<br>
 +
 
 +
==GetCameraZoom==
 +
{{MethodHeader|public native float GetCameraZoom(void)}}
 +
;Parameters
 +
*None
 +
;Returned Value
 +
*Current camera zoom, in meters
 +
;Syntax
 +
float zoom= World.GetCameraZoom();
 +
;Notes
 +
*<font color=red>Is this value equivalent to '''radius''' in [[#SetCameraAngle|SetCameraAngle()]]?</font>
 +
*<font color=red>Added in ...?</font>
 
<br>
 
<br>
  
Line 328: Line 452:
 
*An integer representing the current Trainz module.
 
*An integer representing the current Trainz module.
 
;Syntax
 
;Syntax
  int module = World,GetCurrentModule();
+
  int module = World.GetCurrentModule();
 
;Notes
 
;Notes
 
* See [[#Trainz Modules|Trainz Modules]] for details of the constants associated with this method.  
 
* See [[#Trainz Modules|Trainz Modules]] for details of the constants associated with this method.  
 
* See [[ModuleInit Message]] for further details.
 
* See [[ModuleInit Message]] for further details.
 +
<br>
 +
 +
==GetCurrentProfile==
 +
{{MethodHeader|public native [[Class Asset|Asset]] GetCurrentProfile(void)}}
 +
;Parameters
 +
*None
 +
;Returned Value
 +
*The current session asset
 +
;Syntax
 +
Asset currentSession = World.GetCurrentProfile();
 +
;Notes
 +
*<font color=red>Added in ...?</font>
 +
<br>
 +
 +
==GetCurrentTrain==
 +
{{MethodHeader|public native Train GetCurrentTrain(void)}}
 +
;Parameters
 +
*None
 +
;Returned Value
 +
*The currently focused train
 +
;Syntax
 +
Train myTrain = World.GetCurrentTrain();
 +
;Notes
 +
* The current train is the one currently controlled by the user, which may not be the train the camera is focused on.
 +
*<font color=red>Added in ...?</font>
 
<br>
 
<br>
  
 
==GetDriverCharacterList==
 
==GetDriverCharacterList==
{{MethodHeader|public native DriverCharacter[ ] GetDriverCharacterList(void)}}
+
{{MethodHeader|public native [[Class DriverCharacter|DriverCharacter]][ ] GetDriverCharacterList(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 346: Line 495:
  
 
==GetDriverCommandList==
 
==GetDriverCommandList==
{{MethodHeader|public native DriverCommand[ ] GetDriverCommandList(void)}}
+
{{MethodHeader|public native [[Class DriverCommand|DriverCommand]][ ] GetDriverCommandList(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 354: Line 503:
 
  DriverCommand[] commands = World.GetDriverCommandList();
 
  DriverCommand[] commands = World.GetDriverCommandList();
 
;Notes
 
;Notes
 +
<br>
 +
 +
==GetGameDate==
 +
{{MethodHeader|public native int GetGameDate(void)}}
 +
;Parameters
 +
*None
 +
;Returned value
 +
*Current game day (1 - 31)
 +
;Syntax
 +
int Now = World.GetGameDate();
 +
;Notes
 +
*<font color=red>Added in ...?</font>
 +
<br>
 +
 +
==GetGameMonth==
 +
{{MethodHeader|public native int GetGameMonth(void)}}
 +
;Parameters
 +
*None
 +
;Returned value
 +
*Current game month (1 - 12)
 +
;Syntax
 +
int Now = World.GetGameMonth();
 +
;Notes
 +
*<font color=red>Added in ...?</font>
 +
<br>
 +
 +
==GetGameObjectByID==
 +
{{MethodHeader|public native [[Class AsyncObjectSearchResult|AsyncObjectSearchResult]] GetGameObjectByID([[Class GameObjectID|GameObjectID]] objectID, bool bTriggerLoad)<br>public native [[Class AsyncObjectSearchResult|AsyncObjectSearchResult]] GetGameObjectByID([[Class GameObjectID|GameObjectID]] objectID)}}
 +
;Parameters
 +
*'''objectID''' = The ID of the object to find.
 +
*'''bTriggerLoad''' = Optional, defaults to true. Whether to trigger an asynchronous load of any matching object (if it's not loaded already).
 +
;Returned Value
 +
* Asynchronous search result object.
 +
;Syntax
 +
AsyncObjectSearchResult search_result = World.GetGameObjectByID(objectID, true);  // Search for and load an object
 +
;Notes
 +
*See [[HowTo/Search for objects in the world]] for a detailed guide on asynchronous searches.
 +
*The retured object is a reference to the in-progress object search.
 +
*When the search completes, a message of type "ObjectSearch","AsyncResult" will be posted to the result object.
 +
*If bTriggerLoad is true, a further message of type "ObjectSearch","AsyncLoadComplete" will be posted when all objects are loaded into memory. This message will still be posted if every object is already loaded.
 +
*Added in TRS19
 +
<br>
 +
 +
==GetGameObjectByIDIfLoaded==
 +
{{MethodHeader|public native [[Class GameObject|GameObject]] GetGameObjectByIDIfLoaded([[Class GameObjectID|GameObjectID]] objectID)}}
 +
;Parameters
 +
*'''objectID''' = The ID of the boject to find.
 +
;Returned Value
 +
* The object, if it exists and is currently loaded.
 +
;Syntax
 +
GameObject my_object = World.GetGameObjectByID(objectID);
 +
if (my_object) Interface.Print("Object exists and is loaded");
 +
;Notes
 +
*Added in TRS19
 +
<br>
 +
 +
==GetGameSeason==
 +
{{MethodHeader|public native float GetGameSeason(void)}}
 +
;Parameters
 +
*None
 +
;Returned value
 +
*Current game season
 +
;Syntax
 +
float Season = World.GetGameSeason();
 +
;Notes
 +
*The returned time is normalised to a value between 0.0 and 1.0
 +
*0.0 = mid-summer
 +
*0.5 = mid-winter
 +
*<font color=red>Added in ...?</font>
 
<br>
 
<br>
  
Line 366: Line 584:
 
;Notes
 
;Notes
 
*The returned time is normalised to a value between 0.0 and 1.0
 
*The returned time is normalised to a value between 0.0 and 1.0
*0.0 = midday.
+
*0.0 = midday
 +
*0.25 = 6 p.m.
 
*0.5 = midnight
 
*0.5 = midnight
 +
*0.75 = 6 a.m.
 +
*1.0 = midday again
 
*Use the [[#Time_Values|Time Value]] constants to convert the normalised values to human readable times.
 
*Use the [[#Time_Values|Time Value]] constants to convert the normalised values to human readable times.
 +
<br>
 +
 +
==GetGameYear==
 +
{{MethodHeader|public native int GetGameYear(void)}}
 +
;Parameters
 +
*None
 +
;Returned value
 +
*Current game year.
 +
;Syntax
 +
int Now = World.GetGameYear();
 +
;Notes
 +
*<font color=red>Added in ...?</font>
 
<br>
 
<br>
  
 
==GetGoodWeatherFog==
 
==GetGoodWeatherFog==
{{MethodHeader|public native float GetGoodWeatherFog(void)}}
+
{{MethodHeader|public obsolete native float GetGoodWeatherFog(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 380: Line 613:
 
  float dist = World.GetGoodWeatherFog();
 
  float dist = World.GetGoodWeatherFog();
 
;Notes
 
;Notes
 +
*Obsolete in TRS19
 
<br>
 
<br>
  
 
==GetGroundDrawDistance==
 
==GetGroundDrawDistance==
{{MethodHeader|public native float GetGroundDrawDistance(void)}}
+
{{MethodHeader|public obsolete native float GetGroundDrawDistance(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 394: Line 628:
  
 
==GetIndustryList==
 
==GetIndustryList==
{{MethodHeader|public native GameObject[ ] GetIndustryList(void)}}
+
{{MethodHeader|public obsolete native [[Class GameObject|GameObject]][ ] GetIndustryList(void)}}
 
;Parameters  
 
;Parameters  
 
*None
 
*None
Line 402: Line 636:
 
  GameObject[] Industries = World.GetIndustryList();
 
  GameObject[] Industries = World.GetIndustryList();
 
;Notes
 
;Notes
 +
*This function is obsolete and should not be used. Use [[#GetNamedObjectList|GetNamedObjectList]] instead.
 
<br>
 
<br>
  
 
==GetJunctionList==
 
==GetJunctionList==
{{MethodHeader|public native Junction[ ] GetJunctionList(void)}}
+
{{MethodHeader|public obsolete native [[Class Junction|Junction]][ ] GetJunctionList(void)}}
 
;Parameters  
 
;Parameters  
 
*None
 
*None
Line 413: Line 648:
 
  Junction[] junctions = World.GetJunctionList();
 
  Junction[] junctions = World.GetJunctionList();
 
;Notes
 
;Notes
*Junction objects attached to fixed track junctions are not currently returned by this method.
+
*This function is obsolete and should not be used. Use [[#GetNamedObjectList|GetNamedObjectList]] instead.
 +
*Junction objects attached to fixed track junctions are not returned by this method.
 +
<br>
 +
 
 +
==GetLayerList==
 +
{{MethodHeader|public native string[ ] GetLayerList(int layerType)}}
 +
;Parameters
 +
*layerType = LAYER_ROUTE, LAYER_SESSION, or LAYER_BOTH
 +
;Returned Value
 +
*Array of layer names
 +
;Syntax
 +
string[] routeLayerNames = World.GetLayerList(World.LAYER_ROUTE);
 +
;Notes
 +
*<font color=red>Added in ...?</font>
 +
<br>
 +
 
 +
==GetLayerType==
 +
{{MethodHeader|public native int GetLayerType(string layerName)}}
 +
;Parameters
 +
*layerName = The name of the layer
 +
;Returned Value
 +
*LAYER_ROUTE or LAYER_SESSION
 +
;Syntax
 +
int layerType = World.GetLayerType("MyLayer");
 +
;Notes
 +
*<font color=red>Added in ...?</font>
 
<br>
 
<br>
  
 
==GetLibrary==
 
==GetLibrary==
{{MethodHeader|public native Library GetLibrary(KUID kuid)}}
+
{{MethodHeader|public native [[Class Library|Library]] GetLibrary([[Class KUID|KUID]] kuid)}}
 
;Parameters
 
;Parameters
 
*'''kuid''' = KUID of script library asset to load.
 
*'''kuid''' = KUID of script library asset to load.
Line 430: Line 690:
 
<br>
 
<br>
  
==GetSceneryDrawDistance==
+
==GetLocalPlayerName==
{{MethodHeader|public native float GetSceneryDrawDistance(void)}}
+
{{MethodHeader|public native string GetLocalPlayerName(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
 
;Returned Value
 
;Returned Value
*Scenery draw distance in metres.
+
*The name of the local player
 
;Syntax
 
;Syntax
  float dist = World.GetSceneryDrawDistance();
+
  string playerName = World.GetLocalPlayerName();
 +
;Notes
 +
* Gets the name of the local player, as should be used for setting ownership on DriverCharacters, etc.
 +
*<font color=red>Added in .TRS19?</font>
 +
<br>
 +
 
 +
==GetNamedObjectList==
 +
{{MethodHeader|public native [[Class AsyncObjectSearchResult|AsyncObjectSearchResult]] GetNamedObjectList(string categoryFilter, string nameFilter, bool bNotifyOfExpiry)<br>public [[Class AsyncObjectSearchResult|AsyncObjectSearchResult]] GetNamedObjectList(string categoryFilter, string nameFilter)}}
 +
;Parameters
 +
*'''categoryFilter''' = A category filter to search for. Optional, provided a nameFilter parameter is provided. A category code reference can be found in [[Class AssetCategory|AssetCategory]].
 +
*'''nameFilter''' = A partial object name to search for. Optional, provided a categoryFilter parameter is provided.
 +
*'''bNotifyOfExpiry''' = Optional, defaults to false. If native code detects that the search results have changed then a message of type "ObjectSearch","Expired" will be posted to the result object, and the calling script can perform a new search if desired
 +
;Returned Value
 +
* Asynchronous search result object.
 +
;Syntax
 +
AsyncObjectSearchResult search_result = World.GetNamedObjectList(AssetCategory.Locomotive, "SD40-2"); // Search for all SD40-2 locomotives in the world
 +
;Notes
 +
*See [[HowTo/Search for objects in the world]] for a detailed guide on asynchronous searches.
 +
*The retured object is a reference to the in-progress object search.
 +
*When the search completes, a message of type "ObjectSearch","AsyncResult" will be posted to the result object.
 +
*With expiration notices are enabled, only one notification of type "ObjectSearch","Expired" will be posted for each search.
 +
*Added in TRS19.
 +
*''As personal experience has shown, the number of lines in this list is limited to 1000, so for large routes, unfortunately, such a search is not complete.''
 +
<br>
 +
 
 +
==GetSceneryDrawDistance==
 +
{{MethodHeader|public obsolete native float GetSceneryDrawDistance(void)}}
 +
;Parameters
 +
*None
 +
;Returned Value
 +
*Undefined.
 
;Notes
 
;Notes
 +
*Included for legacy script compatibility only. Has no effect.
 
<br>
 
<br>
  
Line 458: Line 749:
  
 
==GetSignalList==
 
==GetSignalList==
{{MethodHeader|public native Signal[ ] GetSignalList(void)}}
+
{{MethodHeader|public obsolete native [[Class Signal|Signal]][ ] GetSignalList(void)}}
 
;Parameters  
 
;Parameters  
 
*None
 
*None
Line 466: Line 757:
 
  Signal[] signals = World.GetSignalList();
 
  Signal[] signals = World.GetSignalList();
 
;Notes
 
;Notes
 +
*This function is obsolete and should not be used. Use [[#GetNamedObjectList|GetNamedObjectList]] instead.
 
<br>
 
<br>
  
 
==GetStringTable==
 
==GetStringTable==
{{MethodHeader|public native StringTable GetStringTable(void)}}
+
{{MethodHeader|public native [[Class StringTable|StringTable]] GetStringTable(void)}}
 
;Parameters  
 
;Parameters  
 
*None
 
*None
Line 480: Line 772:
  
 
==GetSurveyorSavedConsist==
 
==GetSurveyorSavedConsist==
{{MethodHeader|public native Soup GetSurveyorSavedConsistList(string name)}}
+
{{MethodHeader|public obsolete native [[Class Soup|Soup]] GetSurveyorSavedConsist(string name)}}
 
;Parameters  
 
;Parameters  
*'''name''' = Name of the consist to retireiev.
+
*'''name''' = Name of the consist to retrieve.
 
;Returned Value
 
;Returned Value
 
*Returns a Soup definition of the named consist if it exists, null otherwise.
 
*Returns a Soup definition of the named consist if it exists, null otherwise.
Line 489: Line 781:
 
;Notes
 
;Notes
 
*Remember that the returned data is in a Soup format, which is not the same thing as a Train.  
 
*Remember that the returned data is in a Soup format, which is not the same thing as a Train.  
*TrainUtil.CreateTrainFormSoup() can be used to create a train from the returned Soup.
+
*[[Class TrainUtil#CreateTrainFromSoup|TrainUtil.CreateTrainFromSoup()]] can be used to create a train from the returned Soup.
 
*This method only works in Surveyor.
 
*This method only works in Surveyor.
 +
*Obsolete in TRS19.
 
<br>
 
<br>
  
Line 503: Line 796:
 
;Notes
 
;Notes
 
*This method only works in Surveyor.
 
*This method only works in Surveyor.
 +
*Obsolete in TRS19.
 +
<br>
 +
 +
==GetTimeElapsed==
 +
{{MethodHeader|public native float GetTimeElapsed(void)}}
 +
;Parameters
 +
*None
 +
;Returned Value
 +
*The number of real-time seconds that have passed since the start of the current session.
 +
;Syntax
 +
float secondsElapsed = World.GetTimeElapsed();
 +
;Notes
 +
*This measure of time stops passing while the game is paused.
 +
*<font color=red>Added in ...?</font>
 
<br>
 
<br>
  
 
==GetTrackmarkList==
 
==GetTrackmarkList==
{{MethodHeader|public native TrackMark[ ] GetTrackmarkList(void)}}
+
{{MethodHeader|public obsolete native [[Class TrackMark|TrackMark]][ ] GetTrackmarkList(void)}}
 
;Parameters  
 
;Parameters  
 
*None
 
*None
Line 514: Line 821:
 
  Trackmark[] trackmarks = World.GetTrackmarkList();
 
  Trackmark[] trackmarks = World.GetTrackmarkList();
 
;Notes
 
;Notes
 +
*This function is obsolete and should not be used. Use [[#GetNamedObjectList|GetNamedObjectList]] instead.
 
<br>
 
<br>
  
 
==GetTrainList==
 
==GetTrainList==
{{MethodHeader|public native Train[ ] GetTrainList(void)}}
+
{{MethodHeader|public obsolete native [[Class Train|Train]][ ] GetTrainList(void)}}
 
;Parameters  
 
;Parameters  
 
*None
 
*None
Line 525: Line 833:
 
  Train[] trains = World.GetTrainList();
 
  Train[] trains = World.GetTrainList();
 
;Notes
 
;Notes
 +
*This function is obsolete and should not be used. Use [[#GetNamedObjectList|GetNamedObjectList]] instead.
 
<br>
 
<br>
  
Line 548: Line 857:
 
  float version = World.GetTrainzVersion();
 
  float version = World.GetTrainzVersion();
 
;Notes
 
;Notes
*The value returned corresponds to the version number you can see in the bottom-right side of the main Trainz menu screen.  
+
*The value returned corresponds to the version number of Content manager (for example 4.6).  
 
<br>
 
<br>
  
 
==GetTriggerList==
 
==GetTriggerList==
{{MethodHeader|public native Trigger[ ] GetTriggerList(void)}}
+
{{MethodHeader|public obsolete native [[Class Trigger|Trigger]][ ] GetTriggerList(void)}}
 
;Parameters  
 
;Parameters  
 
*None
 
*None
Line 560: Line 869:
 
  Trigger[] triggers = World.GetTriggerList();
 
  Trigger[] triggers = World.GetTriggerList();
 
;Notes
 
;Notes
 +
*This function is obsolete and should not be used. Use [[#GetNamedObjectList|GetNamedObjectList]] instead.
 
*This method does not return scenery triggers, ie those attached to SceneryWithTrack objects and their descendants.
 
*This method does not return scenery triggers, ie those attached to SceneryWithTrack objects and their descendants.
 
<br>
 
<br>
  
 
==GetVehicleList==
 
==GetVehicleList==
{{MethodHeader|public native Vehicle[ ] GetVehicleList(void)}}
+
{{MethodHeader|public obsolete native [[Class Vehicle|Vehicle]][ ] GetVehicleList(void)}}
 
;Parameters  
 
;Parameters  
 
*None
 
*None
Line 572: Line 882:
 
  Vehicle[] vehicles = World.GetVehicleList();
 
  Vehicle[] vehicles = World.GetVehicleList();
 
;Notes
 
;Notes
 +
*This function is obsolete and should not be used. Use [[#GetNamedObjectList|GetNamedObjectList]] instead.
 
<br>
 
<br>
  
 
==GetWeatherChangeability==
 
==GetWeatherChangeability==
 
{{MethodHeader|public native int GetWeatherChangeability(void)}}
 
{{MethodHeader|public native int GetWeatherChangeability(void)}}
;Parameter
+
;Parameters
 
*None
 
*None
 
;Returned Value
 
;Returned Value
Line 587: Line 898:
 
==GetWeatherType==
 
==GetWeatherType==
 
{{MethodHeader|public native int GetWeatherType(void)}}
 
{{MethodHeader|public native int GetWeatherType(void)}}
;Parameter
+
;Parameters
 
*None
 
*None
 
;Returned Value
 
;Returned Value
Line 594: Line 905:
 
  int weather = World.GetWeatherType();
 
  int weather = World.GetWeatherType();
 
;Notes
 
;Notes
 +
<br>
 +
 +
==IsAssetRestrictionInEffect==
 +
{{MethodHeader|public native bool IsAssetRestrictionInEffect(string)}}
 +
;Parameters
 +
*None
 +
;Returned Value
 +
*Whether this game world has Asset Restrictions.
 +
;Syntax
 +
bool assetRestrictionsExist = World.IsAssetRestrictionInEffect();
 +
;Notes
 +
*Multiplayer Sessions require Asset Restrictions to be in effect to avoid compatibility issues between peers.
 +
*<font color=red>Added in ...?</font>
 +
<br>
 +
 +
==IsLayerVisible==
 +
{{MethodHeader|public native bool IsLayerVisible(string layerName)}}
 +
;Parameter
 +
*layerName = Name of the layer to check
 +
;Returned Value
 +
*Whether the layer is visible
 +
;Syntax
 +
bool isVisible = World.IsLayerVisible("MyLayer");
 +
;Notes
 +
*<font color=red>Added in ...?</font>
 
<br>
 
<br>
  
 
==LoadMap==
 
==LoadMap==
{{MethodHeader|public native bool LoadMap(KUID kuid)}}
+
{{MethodHeader|public native bool LoadMap([[Class KUID|KUID]] kuid)}}
 
;Parameters
 
;Parameters
 
*'''kuid''' = KUID of map to load.
 
*'''kuid''' = KUID of map to load.
Line 606: Line 942:
 
  else Interface.Print("Map load failed");
 
  else Interface.Print("Map load failed");
 
;Notes
 
;Notes
 +
*Use World.[[#FindKUID|FindKUID()]] to find the desired route KUID.
 +
*In multiplayer, this will only succeed on the server.
 +
<br>
 +
 +
==LoadSession==
 +
{{MethodHeader|public native bool LoadSession([[Class KUID|KUID]] kuid)}}
 +
;Parameters
 +
*'''kuid''' = KUID of session to load.
 +
;Returned Value
 +
*True if successful, false otherwise.
 +
;Syntax
 +
if (World.LoadSession(sessionKUID) Interface.Print("Session loaded OK");
 +
else Interface.Print("Session load failed");
 +
;Notes
 +
*Use World.[[#FindKUID|FindKUID()]] to find the desired session KUID.
 +
*In multiplayer, this will only succeed on the server.
 +
*<font color=red>Added in ...?</font>
 
<br>
 
<br>
  
 
==Play2DSound==
 
==Play2DSound==
{{MethodHeader|public float Play2DSound(Asset asset, string wave)}}
+
{{MethodHeader|public float Play2DSound([[Class Asset|Asset]] asset, string wave)}}
 
;Parameters
 
;Parameters
 
*'''asset''' = Asset where the sound file is located.
 
*'''asset''' = Asset where the sound file is located.
 
*'''wave''' = Name of the ''*.wav'' file to be played, a relative path can be included.
 
*'''wave''' = Name of the ''*.wav'' file to be played, a relative path can be included.
 
;Returned Value
 
;Returned Value
*The length of the sound file in seconds.
+
* Undefined.
*In TS12 the returned value is undefined, see notes below under "PlaySound"
+
 
;Syntax
 
;Syntax
 
  // Play the sound and continues script execution.
 
  // Play the sound and continues script execution.
 
     World.Play2DSound(soundAsset,"sounds/allaboard.wav");         
 
     World.Play2DSound(soundAsset,"sounds/allaboard.wav");         
  // Wait until sound has completed before continuing.
+
  // Wait until sound has completed before continuing (pre-TS12 only!)
 
     Sleep(World.Play2DSound(soundAsset,"sounds/allaboard.wav"));  
 
     Sleep(World.Play2DSound(soundAsset,"sounds/allaboard.wav"));  
 
;Notes
 
;Notes
Line 626: Line 978:
 
*This method does not return after the sound has finished playing, it returns with the length of the sound as soon as it is called.  
 
*This method does not return after the sound has finished playing, it returns with the length of the sound as soon as it is called.  
 
*This means your code will keep on executing while Trainz is playing the sound.
 
*This means your code will keep on executing while Trainz is playing the sound.
*If you want to wait for the sound to complete playing before moving on, wrap the Play2DSound() call up in a Sleep() call. ''Doesn't work in TS12, see notes in PlaySound below.''
 
*Remember that Sleep() can't always be used.
 
 
<br>
 
<br>
  
 
==PlaySound==
 
==PlaySound==
{{MethodHeader|public native float PlaySound<br>&nbsp;&nbsp;&nbsp;&nbsp;(Asset asset, string wave, float vol, float near, float far, GameObject target, string pt)<br>&nbsp;&nbsp;&nbsp;&nbsp;(Asset asset, string wave, float vol, float near, float far, GameObject target, string pt, bool loop)}}
+
{{MethodHeader|public native float PlaySound<br>&nbsp;&nbsp;&nbsp;&nbsp;([[Class Asset|Asset]] asset, string wave, float vol, float near, float far, [[Class GameObject|GameObject]] target, string pt)<br>&nbsp;&nbsp;&nbsp;&nbsp;([[Class Asset|Asset]] asset, string wave, float vol, float near, float far, [[Class GameObject|GameObject]] target, string pt, bool loop)}}
 
;Parameters
 
;Parameters
 
*'''asset''' = Asset where the sound file is located.
 
*'''asset''' = Asset where the sound file is located.
 
*'''wave''' = Name of the ''*.wav'' file to be played, a relative path can be included.
 
*'''wave''' = Name of the ''*.wav'' file to be played, a relative path can be included.
*'''vol''' = Volume level to play the sound at
+
*'''vol''' = Volume level to play the sound at (0 to 1)<- These values taken from TRS2019 world.gs file comments
 
*'''near''' = Distance from the target asset at which the sound will be played at maximum volume.
 
*'''near''' = Distance from the target asset at which the sound will be played at maximum volume.
 
*'''far''' = Distance from the target asset at which the sound will become inaudible.
 
*'''far''' = Distance from the target asset at which the sound will become inaudible.
Line 642: Line 992:
 
*'''loop''' = (Optional) If true the sound will loop continuously.
 
*'''loop''' = (Optional) If true the sound will loop continuously.
 
;Returned Value
 
;Returned Value
*<strike>The length of the sound file in seconds.</strike>
+
* Sound length in seconds for Trainz before TS12
*NOTE:  In TS12, the returned value is now undefined, and currently always returns '10'.  This is to remove the performance cost of having to read the file from disk immediately to determine the sound length before the function can complete.  While a fixed value Sleep() would be more efficient, you can can also use Sleep('''wave'''.size()) immediately following the PlaySound to pause execution for the duration of the sound.
+
* Undefined for TS12 and TANE
 
;Syntax
 
;Syntax
 
  // Play the sound and continues script execution.
 
  // Play the sound and continues script execution.
     World.PlaySound(soundAsset,"sounds/allaboard.wav",1000.0,10.0,100.0,Station,"a.loudspeaker");      
+
     World.PlaySound(soundAsset,"sounds/allaboard.wav",1.0,10.0,100.0,Station,"a.loudspeaker");    
  <strike>// Wait until sound has completed before continuing.</strike>
+
  // Wait until sound has completed before continuing (pre-TS12 only!)
<strike>  Sleep(World.PlaySound(soundAsset,"sounds/allaboard.wav",1000.0,10.0,100.0,Station,"a.loudspeaker"));</strike>
+
    Sleep(World.PlaySound(soundAsset,"sounds/allaboard.wav",1000.0,10.0,100.0,Station,"a.loudspeaker");    
 
;Notes
 
;Notes
 
*Plays a ''.wav'' sound file from the given asset's folder.
 
*Plays a ''.wav'' sound file from the given asset's folder.
 
*If the sound is to be directional a mono sound file is required.  
 
*If the sound is to be directional a mono sound file is required.  
*This method does not return after the sound has finished playing, it returns with the length of the sound as soon as it is called.  
+
*This method does not return after the sound has finished playing: it returns as soon as it is called.  
 
*This means your code will keep on executing while Trainz is playing the sound.
 
*This means your code will keep on executing while Trainz is playing the sound.
*If you want to wait for the sound to complete playing before moving on, wrap the PlaySound() call up in a Sleep() call.
+
*If you want to wait for the sound to complete playing before moving on, wrap the PlaySound() call up in a Sleep() call. '''Note!''' This works only in Trainz versions before TS12. For newer versions, TS12 and TANE, you can hard-code the duration of the sound, or store it in the extensions container of the config.txt file.
*Remember that Sleep() can't always be used.
+
 
*The sound volume will be at a maximum for a camera position at or less than the value of the ''near'' parameter and will reduce with distance until the hearing position reaches ''far'', when the sound will be inaudible.
 
*The sound volume will be at a maximum for a camera position at or less than the value of the ''near'' parameter and will reduce with distance until the hearing position reaches ''far'', when the sound will be inaudible.
 
<br>
 
<br>
  
 
==RemoveDriverCharacter==
 
==RemoveDriverCharacter==
{{MethodHeader|public native void RemoveDriverCharacter(DriverCharacter driver)}}
+
{{MethodHeader|public native void RemoveDriverCharacter([[Class DriverCharacter|DriverCharacter]] driver)}}
 
;Parameters
 
;Parameters
 
*'''driver''' = DriverCharacter to remove.
 
*'''driver''' = DriverCharacter to remove.
Line 668: Line 1,017:
 
  World.RemoveDriverCharacter(dave);
 
  World.RemoveDriverCharacter(dave);
 
;Notes
 
;Notes
 +
*In multiplayer, this will only succeed on the server.
 
<br>
 
<br>
  
 
==RemoveDriverCommand==
 
==RemoveDriverCommand==
{{MethodHeader|public native void RemoveDriverCommand(DriverCommand command)}}
+
{{MethodHeader|public native void RemoveDriverCommand([[Class DriverCommand|DriverCommand]] command)}}
 
;Parameters
 
;Parameters
 
*'''command''' = DriverCommand to remove.
 
*'''command''' = DriverCommand to remove.
Line 679: Line 1,029:
 
  World.RemoveDriverCommand(driverCommand);
 
  World.RemoveDriverCommand(driverCommand);
 
;Notes
 
;Notes
 +
*In multiplayer, this will only succeed on the server.
 +
<br>
 +
 +
==RestartSession==
 +
{{MethodHeader|public native bool RestartSession()}}
 +
;Parameters
 +
;Returned Value
 +
*True if successful, false otherwise.
 +
;Syntax
 +
World.RestartSession();
 +
;Notes
 +
*Valid in Driver mode only.
 +
*In multiplayer, this will only succeed on the server.
 
<br>
 
<br>
  
 
==SetBadWeatherFog==
 
==SetBadWeatherFog==
{{MethodHeader|public native void SetBadWeatherFog(float distance)}}
+
{{MethodHeader|public obsolete native void SetBadWeatherFog(float distance)}}
 
;Parameters
 
;Parameters
 
*'''distance''' = Bad weather fog distance to set.
 
*'''distance''' = Bad weather fog distance to set.
Line 690: Line 1,053:
 
  World.SetBadWeatherFog(0.5);
 
  World.SetBadWeatherFog(0.5);
 
;Notes
 
;Notes
 +
*Obsolete in TRS19
 
<br>
 
<br>
  
 
==SetCamera==
 
==SetCamera==
{{MethodHeader|public native bool SetCamera(MapObject focus)<br>public native void SetCamera(Junction focus)<br>public native void SetCamera(Vehicle focus, int cameraMode)<br>public native void SetCamera(Train focus, int cameraMode)}}
+
{{MethodHeader|public native bool SetCamera([[Class MapObject|MapObject]] focus)<br>public native void SetCamera([[Class Junction|Junction]] focus)<br>public native void SetCamera([[Class Vehicle|Vehicle]] focus, int cameraMode)<br>public native void SetCamera([[Class Train|Train]] focus, int cameraMode)}}
 
;Parameters
 
;Parameters
 
*'''focus''' = Object on which the camera is to be focused.
 
*'''focus''' = Object on which the camera is to be focused.
Line 700: Line 1,064:
 
*The first variant returns a boolean to indicate success or failure.
 
*The first variant returns a boolean to indicate success or failure.
 
*Remaining variants do not return a value
 
*Remaining variants do not return a value
'Syntax
+
;Syntax
 
  World.SetCamera(train.GetVehicles[0],World.CAMERA_TRACKING); // sets the camera to track the first vehicle in the train.
 
  World.SetCamera(train.GetVehicles[0],World.CAMERA_TRACKING); // sets the camera to track the first vehicle in the train.
 +
;Notes
 +
*<font color=red>Junction alias removed in TRS19?</font>
 
<br>
 
<br>
  
 
==SetCameraAngle==
 
==SetCameraAngle==
{{MethodHeader|public void SetCameraAngle(int yaw, int pitch, float radius)}}
+
{{MethodHeader|public void SetCameraAngle(float yaw, float pitch, float radius)<br>public obsolete void SetCameraAngle(int yaw, int pitch, float radius)}}
 
;Parameters
 
;Parameters
*'''yaw''' = Camera rotation in degrees, 90 is a direct front view.
+
*'''yaw''' = Camera rotation in radians (float) or degrees (int), 90 is a direct front view.
*'''pitch''' = Camera angle relative to the horizon, 0 is horizontal, 90 points vertically upwards.
+
*'''pitch''' = Camera angle relative to the horizon in radians (float), or degrees (int), 0 is horizontal, 90 points vertically upwards.
 
*'''radius''' = Distance in metres to the object in focus.
 
*'''radius''' = Distance in metres to the object in focus.
 
;Returned Value
 
;Returned Value
Line 715: Line 1,081:
 
  World.SetCameraAngle(90,0,25); // Sets the camera to a direct frontal view at 25 metres from the currently focused object.
 
  World.SetCameraAngle(90,0,25); // Sets the camera to a direct frontal view at 25 metres from the currently focused object.
 
;Notes
 
;Notes
*''Radius'' is measured from the object origin point (0,0,0).
+
*''Radius'' is measured from the object origin point (0,0,0). If there's no target object this will be the distance to the ground.
 +
*Note difference in units of ''yaw'' and ''pitch'' depending in the method signature used.
 +
*The integer version of this method call is obsolete in TRS19.
 
<br>
 
<br>
  
Line 741: Line 1,109:
 
;Notes
 
;Notes
 
*Use one of the [[#Camera_View_Modes|Camera View Modes]] to set the parameter.
 
*Use one of the [[#Camera_View_Modes|Camera View Modes]] to set the parameter.
 +
<br>
 +
 +
==SetEditingCamera==
 +
{{MethodHeader|public void SetEditingCamera([[Class GameObject|GameObject]] actor, bool bIsActorEditingCamera)}}
 +
;Parameter
 +
*'''actor''' = The script who is intended to edit the camera position.
 +
*'''bIsActorEditingCamera''' = True to begin editing, or False to end the editing operation.
 +
;Returned Value
 +
*None
 +
;Syntax
 +
World.SetEditingCamera(myScript, true);
 +
;Notes
 +
*Hints to the caching systems that the camera position is in the process of being changed. This may reduce the amount of streaming that will occur until the change is complete.
 +
*This is intended for use-cases where the decision to move the camera happens in advance of the actual call to [[#SetCamera|SetCamera()]] or etc., for example when the new camera target needs to be streamed in first.
 +
*There is no advantage in calling this unless your code then sleeps/waits before undoing the call.
 +
*It is not required to call this before using SetCamera() etc.
 +
*A boolean state is stored per actor; multiple calls to enable editing on a single actor do not need to be matched to multiple calls to disable editing.
 +
*It is counterproductive to call this when transitioning the camera over a short distance (ie. where the source and target locations can see each other). If jumping to a new location, followed by a visual camera transition at the new location, camera editing may be enabled around the target-selection for the jump, and the jump itself, but should be disabled before proceeding with the transition.
 +
*<font color=red>Added in TRS19?</font>
 +
<br>
 +
 +
==SetGameDate==
 +
{{MethodHeader|public void SetGameDate(int year, int month, int date)}}
 +
;Parameters
 +
*'''year''' = The year to set (1970-2038)
 +
*'''month''' = The month to set (1-12)
 +
*'''day''' = The day to set (1-31)
 +
;Returned Value
 +
*None
 +
;Syntax
 +
World.SetGameDate(2000, 12, 25);  // sets date to 25 December 2000
 +
;Notes
 +
*In multiplayer, this will only succeed on the server.
 +
*<font color=red>Added in ...?</font>
 
<br>
 
<br>
  
Line 753: Line 1,155:
 
;Notes
 
;Notes
 
*Game time is normalised to a value between 0.0 and 1.0
 
*Game time is normalised to a value between 0.0 and 1.0
*0.0 = midday.
+
*0.0 = midday
 +
*0.25 = 6 p.m.
 
*0.5 = midnight
 
*0.5 = midnight
 +
*0.75 = 6 a.m.
 +
*1.0 = midday again
 
*Use the [[#Time_Values|Time Value]] constants to convert human readable times to normalised values.  
 
*Use the [[#Time_Values|Time Value]] constants to convert human readable times to normalised values.  
 
<br>
 
<br>
Line 768: Line 1,173:
 
;Notes
 
;Notes
 
*Use one of the [[#Time_Rate_Constants|Time Rate Constants]] to define the parameter.
 
*Use one of the [[#Time_Rate_Constants|Time Rate Constants]] to define the parameter.
 +
*In multiplayer, this will only succeed on the server.
 
<br>
 
<br>
  
 
==SetGoodWeatherFog==
 
==SetGoodWeatherFog==
{{MethodHeader|public native void SetGoodWeatherFog(float distance)}}
+
{{MethodHeader|public obsolete native void SetGoodWeatherFog(float distance)}}
 
;Parameters
 
;Parameters
 
*'''distance''' = Good weather fog distance to set.
 
*'''distance''' = Good weather fog distance to set.
Line 779: Line 1,185:
 
  World.SetGoodWeatherFog(0.5);
 
  World.SetGoodWeatherFog(0.5);
 
;Notes
 
;Notes
 +
*Obsolete in TRS19
 
<br>
 
<br>
  
 
==SetGroundDrawDistance==
 
==SetGroundDrawDistance==
{{MethodHeader|public native void SetGroundDrawDistance(float distance)}}
+
{{MethodHeader|public obsolete native void SetGroundDrawDistance(float distance)}}
 
;Parameters
 
;Parameters
 
*'''distance''' = Ground draw distance in metres.
 
*'''distance''' = Ground draw distance in metres.
Line 791: Line 1,198:
 
;Notes
 
;Notes
 
*Compatibility warning: Use of this function is not recommended, it may become non-functional in future Trainz versions.
 
*Compatibility warning: Use of this function is not recommended, it may become non-functional in future Trainz versions.
 +
<br>
 +
 +
==SetLayerVisible==
 +
{{MethodHeader|public native void IsLayerVisible(string layerName, bool visible)}}
 +
;Parameter
 +
*layerName = Name of the layer to check
 +
*visible = Whether to set the layer visible or not
 +
;Returned Value
 +
*None
 +
;Syntax
 +
World.IsLayerVisible("MyLayer", False);
 +
;Notes
 +
*Show/Hide a route/session layer.
 +
*In multiplayer, this will only succeed on the server.
 +
*<font color=red>Added in ...?</font>
 
<br>
 
<br>
  
 
==SetSceneryDrawDistance==
 
==SetSceneryDrawDistance==
{{MethodHeader|public native void SetSceneryDrawDistance(float distance)}}
+
{{MethodHeader|public obsolete native void SetSceneryDrawDistance(float distance)}}
 
;Parameters
 
;Parameters
*'''distance''' = Scenery draw distance in metres.
+
*'''distance''' = unused.
 
;Returned Value
 
;Returned Value
 
*None
 
*None
;Syntax
 
World.SetSceneryDrawDistance(1000.0);
 
 
;Notes
 
;Notes
*Compatibility warning: Use of this function is not recommended, it may become non-functional in future Trainz versions.  
+
* Does nothing. Included for script compatibility only.
*In TS12 is OBSOLETE.
+
 
<br>
 
<br>
  
 
==SetTargetObserver==
 
==SetTargetObserver==
{{MethodHeader|public void SetTargetObserver(GameObject observer)}}
+
{{MethodHeader|public void SetTargetObserver([[Class GameObject|GameObject]] observer)}}
 
;Parameters
 
;Parameters
*'''observer''' = ?
+
*'''observer''' = The game object to receive targeting messages.
 
;Returned Value
 
;Returned Value
 
*None
 
*None
 
;Syntax
 
;Syntax
  ?
+
  SetTargetObserver(self);
 
;Notes
 
;Notes
*<font color=red>One of the great unsolved mysteries of Trainz</font>
+
* It is unlikely a script programmer would ever need to use this method.
 +
* Causes the specified object to receive "Track", "LeftClick" messages when a track is clicked. Causes the specified object to receive "Interface-Event", "Left-Click" messages when a targetable MapObject is clicked. May cause the functionality of a left mouse click to change from what the user is expecting, so should be used with caution. Used in modal scripts to allow the user to indicate a location for train placement, etc. As there is only a single observer at any given time, the script must take care to only call this function when entering placement mode at the user's request.
 
<br>
 
<br>
  
Line 828: Line 1,248:
 
  World.SetWeather(World.WEATHER_TYPE_HEAVY_SNOW,World.WEATHER_CHANGEABILITY_EXTREME); // April in Paris.
 
  World.SetWeather(World.WEATHER_TYPE_HEAVY_SNOW,World.WEATHER_CHANGEABILITY_EXTREME); // April in Paris.
 
;Notes
 
;Notes
 +
<br>
 +
 +
==SetWorldEditModeEnabled==
 +
{{MethodHeader|public native bool SetWorldEditModeEnabled(int editFlags, bool enable)}}
 +
;Parameters
 +
*'''editFlags''' = Bitmask specifying which modes to alter, see PERMIT_EDIT_*
 +
*''cameraMode''' = Whether to enable or disable the mode
 +
;Returned Value
 +
*Whether the change was completely successful
 +
;Syntax
 +
World.SetWorldEditModeEnabled(World.PERMIT_EDIT_TRAINS | World.PERMIT_EDIT_CONSISTS, True); // Enable player editing of trains and consists
 +
;Notes
 +
*This does not affect scripts which may alter the world, only the availability of the player world editing tools (i.e, the Surveyor tabs).
 +
*<font color=red>Added in TRS19?</font>
 +
<br>
 +
 +
==SynchronouslyLoadGameObjectByID==
 +
{{MethodHeader|public [[Class GameObject|GameObject]] SynchronouslyLoadGameObjectByID([[Class GameObjectID|GameObjectID]] objectID)}}
 +
;Parameters
 +
*'''objectID''' = The ID of the object to find.
 +
;Returned Value
 +
* The object, if it exists.
 +
;Syntax
 +
GameObject my_object = World.SynchronouslyLoadGameObjectByID(objectID);
 +
if (my_object Interface.Print("Object exists and has been loaded if required");
 +
;Notes
 +
*This function is usable only by script 'thread' functions and will throw an exception if called incorrectly.
 +
*Added in TRS19
 +
<br>
 +
 +
==UpdatePositionToGroundHeight==
 +
{{MethodHeader|public native bool UpdatePositionToGroundHeight([[Class WorldCoordinate|WorldCoordinate]] position)}}
 +
;Parameters
 +
*'''position''' (in, out) = Position object to update with the ground height at it's location
 +
;Returned Value
 +
* True if the ground position was updated
 +
;Syntax
 +
if (World.UpdatePositionToGroundHeight(position) Interface.Print("Position was updated");
 +
;Notes
 +
*This updates the input ''position'' object with the ground height at that location.
 +
*This process may fail if the ground data at the specified location is not currently loaded.
 +
*<font color=red>Added in TRS19?</font>
 +
<br>
 +
 +
==UpdatePositionToSurfaceHeight==
 +
{{MethodHeader|public native bool UpdatePositionToSurfaceHeight([[Class WorldCoordinate|WorldCoordinate]] position)}}
 +
;Parameters
 +
*'''position''' (in, out) = Position object to update with the water height at it's location
 +
;Returned Value
 +
* True if the ground position was updated
 +
;Syntax
 +
if (World.UpdatePositionToGroundHeight(position) Interface.Print("Position was updated");
 +
;Notes
 +
*This updates the input ''position'' object with the water height at that location. If no water is present, the position is adjusted to the ground height.
 +
*This process may fail if the ground data at the specified location is not currently loaded.
 +
*<font color=red>Added in TRS19?</font>
 
<br>
 
<br>
  
 
==UserSetCamera==
 
==UserSetCamera==
{{MethodHeader|public native bool UserSetCamera(GameObject target)}}
+
{{MethodHeader|public native bool UserSetCamera([[Class GameObject|GameObject]] target)}}
 
;Parameters
 
;Parameters
 
*'''target''' = GameObject to set focus to.
 
*'''target''' = GameObject to set focus to.
Line 853: Line 1,329:
 
<br>
 
<br>
  
 +
==UserSetCameraPosition==
 +
{{MethodHeader|public native bool UserSetCamera([[Class WorldCoordinate|WorldCoordinate]] camPos)}}
 +
;Parameters
 +
*'''camPos''' = World coordinates to set camera to
 +
;Returned Value
 +
*True if successful, false otherwise.
 +
;Syntax
 +
World.UserSetCamera(Router,GetGameObject("Junction 5"));
 +
;Notes
 +
* For camera modes which do not need to target specific objects, this allows the camera to be set to an arbitrary world position.
 +
*<font color=red>Added in TRS19?</font>
 +
<br>
  
 
==Categories==
 
==Categories==
 
[[Category:Script Class]]
 
[[Category:Script Class]]

Latest revision as of 01:42, 30 July 2022


  • World is a static class used to access various aspects of the Trainz environment.


Contents

[edit] Constants

  • These constants are used to define various values and can be used as mnenomics.
  • If accessed from scripts the values must be prefixed World., for example:
World.SetWeather(World.WEATHER_TYPE_LIGHT_SNOW,World.WEATHER_CHANGEABILITY_PERIODIC);


[edit] Camera View Modes


  • These values can be used either to choose the current camera viewing mode through World.SetCameraMode(), or to restrict certain camera modes from being accessed through methods such as World.SetCamera().
public define int CAMERA_INTERNAL = 1 Internal cabin camera view.
public define int CAMERA_EXTERNAL = 2 External train camera view
public define int CAMERA_TRACKING = 4 External tracking camera view.
public define int CAMERA_ROAMING = 128 Roaming camera view.


[edit] Camera Flags


  • These flags are used in addition to the Camera Mode Flags to allow or disallow specific camera actions.
public define int CAMERA_SWITCH_VIEWS = 8 User permitted to swap between the camera views.
public define int CAMERA_SWITCH_VEHICLES = 16 User permitted to swap vehicles within the current train.
public define int CAMERA_SWITCH_TRAINS = 32 User permitted to swap to other trains which are in the consist menu.
public define int CAMERA_LOCKED = 64 User is NOT permitted to adjust camera (i.e. zoom, pan etc.).
public define int CAMERA_NORMAL = * Normal camera mode where everything is permitted.
* NOTE: CAMERA_NORMAL = CAMERA_INTERNAL | CAMERA_EXTERNAL | CAMERA_TRACKING | CAMERA_SWITCH_VIEWS | CAMERA_SWITCH_VEHICLES | CAMERA_SWITCH_TRAINS


[edit] Weather Type Constants


  • Define the current state of the weather in Trainz.
  • A variety of weather conditions are supported and can be changed by using one of these values with the World.SetWeather() method.
public define int WEATHER_TYPE_CLEAR = 0 Clear weather, no clouds, rain or snow.
public define int WEATHER_TYPE_CLOUDY = 1 Cloudy weather, no rain.
public define int WEATHER_TYPE_DRIZZLE = 2 Drizzle, light rain.
public define int WEATHER_TYPE_RAIN = 3 Rainy weather.
public define int WEATHER_TYPE_STORMY = 4 Stormy weather that includes lightning and thunder.
public define int WEATHER_TYPE_LIGHT_SNOW = 5 Snowing lightly.
public define int WEATHER_TYPE_MEDIUM_SNOW = 6 Medium level snow fall.
public define int WEATHER_TYPE_HEAVY_SNOW = 7 Heavy snow fall.


[edit] Weather Changeability Constants


  • Define the changeability settings for the weather.
  • Weather changeability refers to variability of weather conditions rather than to a specific weather type.
public define int WEATHER_CHANGEABILITY_NONE = 0 Weather remains static.
public define int WEATHER_CHANGEABILITY_PERIODIC = 1 Periodic changes in weather.
public define int WEATHER_CHANGEABILITY_EXTREME = 2 Extreme and frequent changes in weather.


[edit] Time Values


  • Time constants defined in seconds.
public define float TIME_SECOND = 1.0f One second.
public define float TIME_MINUTE = TIME_SECOND * 60.0f One minute, 60.0 seconds.
public define float TIME_HOUR = TIME_MINUTE * 60.0f One hour, 60.0 minutes, 3600.0 seconds.
public define float TIME_DAY = TIME_HOUR * 24.0f One day, 24 hours, 1440.0 minutes, 86400.0 seconds.


[edit] Time Rate Constants


  • Values that define the time rates relative to normal time.
  • These constants can be used to set the time rate that Trainz runs out through the World.SetGameTimeRate() method.
public define int TIME_RATE_1X = 0 Real time (i.e. time in Trainz passes at the same rate as in the real world)
public define int TIME_RATE_2X = 1 Time passes at twice normal speed.
public define int TIME_RATE_4X = 2
public define int TIME_RATE_8X = 3
public define int TIME_RATE_16X = 4
public define int TIME_RATE_32X = 5
public define int TIME_RATE_60X = 6
public define int TIME_RATE_120X = 7
public define int TIME_RATE_240X = 8
public define int TIME_RATE_360X = 9
public define int TIME_RATE_480X = 10
public define int TIME_RATE_720X = 11
public define int TIME_RATE_960X = 12
public define int TIME_RATE_1200X = 13
public define int TIME_RATE_1440X = 14


[edit] Layer Type Constants


public define int LAYER_INVALID = 0
public define int LAYER_ROUTE = 1
public define int LAYER_SESSION = 2
public define int LAYER_BOTH = 3


[edit] World Editing Mode Constants


public define int PERMIT_EDIT_NONE = 0x0
public define int PERMIT_EDIT_TOPOLOGY = 0x1
public define int PERMIT_EDIT_PAINT = 0x2
public define int PERMIT_EDIT_SCENERYOBJECTS = 0x4
public define int PERMIT_EDIT_SCENERYSPLINES = 0x8
public define int PERMIT_EDIT_TRACKSPLINES = 0x10
public define int PERMIT_EDIT_TRACKSIDEOBJECTS = 0x20
public define int PERMIT_EDIT_TRACKMARKS = 0x40
public define int PERMIT_EDIT_TOOLS = 0x80
public define int PERMIT_EDIT_WORLD = 0x100
public define int PERMIT_EDIT_LAYERS = 0x200
public define int PERMIT_EDIT_TRAINS = 0x400
public define int PERMIT_EDIT_CONSISTS = 0x800
public define int PERMIT_EDIT_ALL = -1


[edit] Trainz Modules


  • Trainz module mode constants.
  • These values define the various module environments that Trainz can be in.
public define int NO_MODULE = 0 Trainz not running in a module.
public define int SURVEYOR_MODULE = 1 Trainz is currently running in Surveyor.
public define int DRIVER_MODULE = 2 Trainz is currently running in Driver.


[edit] Related Messages


[edit] AddDriverCharacter

public native DriverCharacter AddDriverCharacter(Asset driverCharacterAsset)
Parameters
  • driverCharacterAsset = Asset containing character to be added.
Returned Value
  • Reference to the DriverCharacter if successful, null otherwise.
Syntax
DriverCharacter Casey = World.AddDriverCharacter(CaseyJones);
Notes
  • In multiplayer, this will only succeed on the server.


[edit] AddDriverCommand

public native DriverCommand AddDriverCommand(Asset driverCommandAsset)
Parameters
  • driverCommandAsset = Asset containing command to be added.
Returned Value
  • Reference to the DriverCommand if successful, null otherwise.
Syntax
DriverCommand GoFaster = World.AddDriverCommand(accelerate);
Notes
  • In multiplayer, this will only succeed on the server.


[edit] CancelCurrentEditingMode

public native void CancelCurrentEditingMode(void)
Parameters
  • None
Returned Value
  • None
Syntax
World.CancelCurrentEditingMode();
Notes
  • Cancels out of any player entered editing mode, if relevant. This should only normally be called as a result of direct player action.
  • Added in TRS19?


[edit] CreateBehavior

public native ScenarioBehavior CreateBehavior(KUID kuid, Soup initialProperties)
Parameters
  • kuid = KUID of scenario.

initialProperties = Soup object containing initial properties for scenario.

Returned Value
  • Reference to the ScenarioBehavior created if successful, null otherwise.
Syntax
ScenarioBehavior scenario = World.CreateBehavior(scenarioAsset, scenarioSoup);
Notes
  • The returned ScenarioBehavior object may be ended by releasing all references to it (resetting all references to null).


[edit] CreateTrain

public native Train CreateTrain(KUID[ ] consist, string trackmarkName, bool direction)
public native Train CreateTrain(KUID[ ] consist, TrackMark trackmark, bool direction)
public native Train CreateTrain(KUID[ ] consist, Buildable buildable, string trackName, float position, bool direction)
public native Train CreateTrain(KUID[ ] consist, GSTrackSearch tracksearch, bool avoidDerailments)
public native Train CreateTrain(KUID[ ] consist, GSTrackSearch tracksearch)
Parameters
  • consist = An array of vehicle KUIDs used to describe the required Train object.
  • trackmarkName = Name of Trackmark at which the consist is to be formed.
  • buildable = Buildable on which the consist is to be formed.
  • trackName = Name of track within Buildable object.
  • position = Distance at which the Train is to be placed relative to the start of the track.
  • trackmark = Reference to Trackmark at which the consist is to be formed.
  • direction = Orientation of Train relative to direction of track or trackmark.
  • tracksearch = The location at which to create the train
  • avoidDerailments = If true this function will fail and return null if creating the train would cause a derailment
Returned Value
  • Reference to the Train created if successful, null otherwise.
Syntax
Train train = World.CreateTrain(consist, buildable, "Track 1", 10.0, true);
Notes
  • These methods create a train from a list of vehicles in a consist array.
  • Depending on the variant of the method used, the train can be created at a Trackmark, specified by name or reference, or at a Buildable or Industry object.
  • It is the responsibility of the script programmer to ensure that sufficient track exists at the given location to allow the train to be created.
  • In multiplayer, this will only succeed on the server.
  • GSTrackSearch aliases added in TRS19?


[edit] DeleteTrain

public native void DeleteTrain(Train train)
Parameters
  • train = train to be deleted from map.
Returned Value
  • None
Syntax
World.DeleteTrain(flyingScotsman);
Notes
  • Once a train has been deleted, care should be taken to avoid using its reference.
  • In multiplayer, this will only succeed on the server.


[edit] DeleteVehicle

public native void DeleteVehicle(Vehicle vehicle)
Parameters
  • vehicle = vehicle to be deleted from its train.
Returned Value
  • None
Syntax
World.DeleteVehicle(vehicles[vehicles.size()-1]);
Notes
  • Use Train.GetVehicles() to obtain an array of vehicles for a given train.
  • Use Vehicle.GetMyTrain() to obtain a train reference for a given vehicle.
  • In multiplayer, this will only succeed on the server.


[edit] EndScenario

public void EndScenario(float time)
Parameters
  • time = Amount of seconds to delay before ending the session
Returned Value
  • None
Syntax
World.EndScenario(30.0);
Notes
  • In multiplayer, this will only succeed on the server.


[edit] FindAsset

public native Asset FindAsset(KUID kuid)
Parameters
  • kuid = KUID of Asset to return.
Returned Value
  • Given a valid KUID parameter, this method return an Asset reference if successful, null otherwise.
Syntax
Asset asset = World.FindAsset(kuid);
Notes
  • See also Asset.FindAsset()


[edit] FindDriverCommand

public native DriverCommand FindDriverCommand(Asset driverCommandAsset)
Parameters
  • driverCommandAsset = Asset containing command to be added.
Returned Value
  • Reference to the DriverCommand if successful, null otherwise.
Syntax
DriverCommand GoFaster = World.FindDriverCommand(accelerate);
Notes


[edit] GetAssetList

public native Asset[ ] GetAssetList(string kind)
Parameters
  • kind = String representing the Kind of asset to return.
Returned Value
  • A list of all assets of the given kind
Syntax
Asset[] Libraries = World.GetAssetList("Library");
Notes
  • All installed assets of the given kind are returned, irrespective of whether or not they are in use on the current map.


[edit] GetBadWeatherFog

public obsolete native float GetBadWeatherFog(void)
Parameters
  • None
Returned Value
  • Bad weather fog distance as a float in the range 0.0..1.0.
Syntax
float dist = World.GetBadWeatherFog();
Notes
  • Obsolete in TRS19


[edit] GetBehaviors

public native ScenarioBehavior[ ] GetBehaviors(void)
Parameters
  • None
Returned Value
  • A list of top-level behaviors or rules on the currently loaded route.
Syntax
ScenarioBehavior[] rules = World.GetBehaviors();
Notes


[edit] GetCameraPitch

public native float GetCameraPitch(void)
Parameters
  • None
Returned Value
  • Current camera pitch, in radians
Syntax
float pitch = World.GetCameraPitch();
Notes
  • Added in ...?


[edit] GetCameraPositionX

public obsolete native float GetCameraPositionX(void)
Parameters
  • None
Returned Value
  • X Coordinate of the current camera position.
Syntax
float X = World.GetCameraPositionX();
Notes
  • Obsolete in TRS19


[edit] GetCameraPositionY

public obsolete native float GetCameraPositionY(void)
Parameters
  • None
Returned Value
  • Y Coordinate of the current camera position.
Syntax
float Y = World.GetCameraPositionY();
Notes
  • Obsolete in TRS19


[edit] GetCameraPositionZ

public obsolete native float GetCameraPositionZ(void)
Parameters
  • None
Returned Value
  • Z Coordinate of the current camera position.
Syntax
float Z = World.GetCameraPositionZ();
Notes
  • Obsolete in TRS19


[edit] GetCameraYaw

public native float GetCameraYaw(void)
Parameters
  • None
Returned Value
  • Current camera yaw, in radians
Syntax
float yaw = World.GetCameraYaw();
Notes
  • Added in ...?


[edit] GetCameraZoom

public native float GetCameraZoom(void)
Parameters
  • None
Returned Value
  • Current camera zoom, in meters
Syntax
float zoom= World.GetCameraZoom();
Notes


[edit] GetCurrentModule

public native int GetCurrentModule(void)
Parameters
  • None
Returned Value
  • An integer representing the current Trainz module.
Syntax
int module = World.GetCurrentModule();
Notes


[edit] GetCurrentProfile

public native Asset GetCurrentProfile(void)
Parameters
  • None
Returned Value
  • The current session asset
Syntax
Asset currentSession = World.GetCurrentProfile();
Notes
  • Added in ...?


[edit] GetCurrentTrain

public native Train GetCurrentTrain(void)
Parameters
  • None
Returned Value
  • The currently focused train
Syntax
Train myTrain = World.GetCurrentTrain();
Notes
  • The current train is the one currently controlled by the user, which may not be the train the camera is focused on.
  • Added in ...?


[edit] GetDriverCharacterList

public native DriverCharacter[ ] GetDriverCharacterList(void)
Parameters
  • None
Returned Value
  • An array of DriverCharacter objects installed in the current world.
Syntax
DriverCharacter[] drivers = World.GetDriverCharacterList();
Notes


[edit] GetDriverCommandList

public native DriverCommand[ ] GetDriverCommandList(void)
Parameters
  • None
Returned Value
  • An array of DriverCommand objects installed in the current world.
Syntax
DriverCommand[] commands = World.GetDriverCommandList();
Notes


[edit] GetGameDate

public native int GetGameDate(void)
Parameters
  • None
Returned value
  • Current game day (1 - 31)
Syntax
int Now = World.GetGameDate();
Notes
  • Added in ...?


[edit] GetGameMonth

public native int GetGameMonth(void)
Parameters
  • None
Returned value
  • Current game month (1 - 12)
Syntax
int Now = World.GetGameMonth();
Notes
  • Added in ...?


[edit] GetGameObjectByID

public native AsyncObjectSearchResult GetGameObjectByID(GameObjectID objectID, bool bTriggerLoad)
public native AsyncObjectSearchResult GetGameObjectByID(GameObjectID objectID)
Parameters
  • objectID = The ID of the object to find.
  • bTriggerLoad = Optional, defaults to true. Whether to trigger an asynchronous load of any matching object (if it's not loaded already).
Returned Value
  • Asynchronous search result object.
Syntax
AsyncObjectSearchResult search_result = World.GetGameObjectByID(objectID, true);  // Search for and load an object
Notes
  • See HowTo/Search for objects in the world for a detailed guide on asynchronous searches.
  • The retured object is a reference to the in-progress object search.
  • When the search completes, a message of type "ObjectSearch","AsyncResult" will be posted to the result object.
  • If bTriggerLoad is true, a further message of type "ObjectSearch","AsyncLoadComplete" will be posted when all objects are loaded into memory. This message will still be posted if every object is already loaded.
  • Added in TRS19


[edit] GetGameObjectByIDIfLoaded

public native GameObject GetGameObjectByIDIfLoaded(GameObjectID objectID)
Parameters
  • objectID = The ID of the boject to find.
Returned Value
  • The object, if it exists and is currently loaded.
Syntax
GameObject my_object = World.GetGameObjectByID(objectID);
if (my_object) Interface.Print("Object exists and is loaded");
Notes
  • Added in TRS19


[edit] GetGameSeason

public native float GetGameSeason(void)
Parameters
  • None
Returned value
  • Current game season
Syntax
float Season = World.GetGameSeason();
Notes
  • The returned time is normalised to a value between 0.0 and 1.0
  • 0.0 = mid-summer
  • 0.5 = mid-winter
  • Added in ...?


[edit] GetGameTime

public native float GetGameTime(void)
Parameters
  • None
Returned value
  • Current game time.
Syntax
float Now = World.GetGameTime();
Notes
  • The returned time is normalised to a value between 0.0 and 1.0
  • 0.0 = midday
  • 0.25 = 6 p.m.
  • 0.5 = midnight
  • 0.75 = 6 a.m.
  • 1.0 = midday again
  • Use the Time Value constants to convert the normalised values to human readable times.


[edit] GetGameYear

public native int GetGameYear(void)
Parameters
  • None
Returned value
  • Current game year.
Syntax
int Now = World.GetGameYear();
Notes
  • Added in ...?


[edit] GetGoodWeatherFog

public obsolete native float GetGoodWeatherFog(void)
Parameters
  • None
Returned Value
  • Good weather fog distance as a float in the range 0.0..1.0.
Syntax
float dist = World.GetGoodWeatherFog();
Notes
  • Obsolete in TRS19


[edit] GetGroundDrawDistance

public obsolete native float GetGroundDrawDistance(void)
Parameters
  • None
Returned Value
  • Ground draw distance in metres.
Syntax
float dist = World.GetGroundDrawDistance();
Notes


[edit] GetIndustryList

public obsolete native GameObject[ ] GetIndustryList(void)
Parameters
  • None
Returned Value
  • An array of references to all of the Industry objects for the current route.
Syntax
GameObject[] Industries = World.GetIndustryList();
Notes


[edit] GetJunctionList

public obsolete native Junction[ ] GetJunctionList(void)
Parameters
  • None
Returned Value
  • An array of references to all of the trackside junction objects for the current route.
Syntax
Junction[] junctions = World.GetJunctionList();
Notes
  • This function is obsolete and should not be used. Use GetNamedObjectList instead.
  • Junction objects attached to fixed track junctions are not returned by this method.


[edit] GetLayerList

public native string[ ] GetLayerList(int layerType)
Parameters
  • layerType = LAYER_ROUTE, LAYER_SESSION, or LAYER_BOTH
Returned Value
  • Array of layer names
Syntax
string[] routeLayerNames = World.GetLayerList(World.LAYER_ROUTE);
Notes
  • Added in ...?


[edit] GetLayerType

public native int GetLayerType(string layerName)
Parameters
  • layerName = The name of the layer
Returned Value
  • LAYER_ROUTE or LAYER_SESSION
Syntax
int layerType = World.GetLayerType("MyLayer");
Notes
  • Added in ...?


[edit] GetLibrary

public native Library GetLibrary(KUID kuid)
Parameters
  • kuid = KUID of script library asset to load.
Returned Value
  • A reference to the script library asset if successful, null otherwise.
Syntax
Library codelib = World.GetLibrary(LibraryKUID);
Notes
  • The Library asset is initialised when this method is first called in a session.
  • Since only one instance can exist, subsequent calls return a reference to the existing Library object.
  • See Library for notes on how to use this method.


[edit] GetLocalPlayerName

public native string GetLocalPlayerName(void)
Parameters
  • None
Returned Value
  • The name of the local player
Syntax
string playerName = World.GetLocalPlayerName();
Notes
  • Gets the name of the local player, as should be used for setting ownership on DriverCharacters, etc.
  • Added in .TRS19?


[edit] GetNamedObjectList

public native AsyncObjectSearchResult GetNamedObjectList(string categoryFilter, string nameFilter, bool bNotifyOfExpiry)
public AsyncObjectSearchResult GetNamedObjectList(string categoryFilter, string nameFilter)
Parameters
  • categoryFilter = A category filter to search for. Optional, provided a nameFilter parameter is provided. A category code reference can be found in AssetCategory.
  • nameFilter = A partial object name to search for. Optional, provided a categoryFilter parameter is provided.
  • bNotifyOfExpiry = Optional, defaults to false. If native code detects that the search results have changed then a message of type "ObjectSearch","Expired" will be posted to the result object, and the calling script can perform a new search if desired
Returned Value
  • Asynchronous search result object.
Syntax
AsyncObjectSearchResult search_result = World.GetNamedObjectList(AssetCategory.Locomotive, "SD40-2"); // Search for all SD40-2 locomotives in the world
Notes
  • See HowTo/Search for objects in the world for a detailed guide on asynchronous searches.
  • The retured object is a reference to the in-progress object search.
  • When the search completes, a message of type "ObjectSearch","AsyncResult" will be posted to the result object.
  • With expiration notices are enabled, only one notification of type "ObjectSearch","Expired" will be posted for each search.
  • Added in TRS19.
  • As personal experience has shown, the number of lines in this list is limited to 1000, so for large routes, unfortunately, such a search is not complete.


[edit] GetSceneryDrawDistance

public obsolete native float GetSceneryDrawDistance(void)
Parameters
  • None
Returned Value
  • Undefined.
Notes
  • Included for legacy script compatibility only. Has no effect.


[edit] GetSeconds

public native float GetSeconds(void)
Parameters
  • None
Returned Value
  • The current value of a floating point number incrementing once per second in real time.
Syntax
float start = World.GetSeconds();
// do stuff
float finish = World.GetSeconds();
float period = finish - start;
Notes
  • Each call will return a float value containing the current value of an internal counter.
  • Subtracting a later value from a value saved at an earlier call will enable the delay between the two calls to be established.


[edit] GetSignalList

public obsolete native Signal[ ] GetSignalList(void)
Parameters
  • None
Returned Value
  • An array of references to all of the signal objects for the current route.
Syntax
Signal[] signals = World.GetSignalList();
Notes


[edit] GetStringTable

public native StringTable GetStringTable(void)
Parameters
  • None
Returned Value
  • The StringTable for the current session.
Syntax
StringTable data = World.GetStringTable();
Notes


[edit] GetSurveyorSavedConsist

public obsolete native Soup GetSurveyorSavedConsist(string name)
Parameters
  • name = Name of the consist to retrieve.
Returned Value
  • Returns a Soup definition of the named consist if it exists, null otherwise.
Syntax
Soup consist = World.GetSurveyorSavedConsist("Brighton Belle");
Notes
  • Remember that the returned data is in a Soup format, which is not the same thing as a Train.
  • TrainUtil.CreateTrainFromSoup() can be used to create a train from the returned Soup.
  • This method only works in Surveyor.
  • Obsolete in TRS19.


[edit] GetSurveyorSavedConsistList

public native string[ ] GetSurveyorSavedConsistList()
Parameters
  • None
Returned Value
  • An array of names of all the saved consist objects in Surveyor.
Syntax
string[] consists = World.GetSurveyorSavedConsistList();
Notes
  • This method only works in Surveyor.
  • Obsolete in TRS19.


[edit] GetTimeElapsed

public native float GetTimeElapsed(void)
Parameters
  • None
Returned Value
  • The number of real-time seconds that have passed since the start of the current session.
Syntax
float secondsElapsed = World.GetTimeElapsed();
Notes
  • This measure of time stops passing while the game is paused.
  • Added in ...?


[edit] GetTrackmarkList

public obsolete native TrackMark[ ] GetTrackmarkList(void)
Parameters
  • None
Returned Value
  • An array of references to all of the trackmark objects for the current route.
Syntax
Trackmark[] trackmarks = World.GetTrackmarkList();
Notes


[edit] GetTrainList

public obsolete native Train[ ] GetTrainList(void)
Parameters
  • None
Returned Value
  • An array of references to all of the trains for the current route.
Syntax
Train[] trains = World.GetTrainList();
Notes


[edit] GetTrainzBuild

public native int GetTrainzBuild(void)
Parameters;
  • None
Returned Value
  • Gets the current build number of Trainz.
Syntax
int build = World.GetTrainzBuild();
Notes
  • The value returned corresponds to the build number you can see in the bottom-right side of the main Trainz menu screen.


[edit] GetTrainzVersion

public native float GetTrainzVersion(void)
Parameters
  • None
Returned Value
  • The TRS version number.
Syntax
float version = World.GetTrainzVersion();
Notes
  • The value returned corresponds to the version number of Content manager (for example 4.6).


[edit] GetTriggerList

public obsolete native Trigger[ ] GetTriggerList(void)
Parameters
  • None
Returned Value
  • An array of references to all of the trigger objects for the current route.
Syntax
Trigger[] triggers = World.GetTriggerList();
Notes
  • This function is obsolete and should not be used. Use GetNamedObjectList instead.
  • This method does not return scenery triggers, ie those attached to SceneryWithTrack objects and their descendants.


[edit] GetVehicleList

public obsolete native Vehicle[ ] GetVehicleList(void)
Parameters
  • None
Returned Value
  • An array of references to all of the vehicles in the current route.
Syntax
Vehicle[] vehicles = World.GetVehicleList();
Notes


[edit] GetWeatherChangeability

public native int GetWeatherChangeability(void)
Parameters
  • None
Returned Value
Syntax
int variability = World.GetWeatherChangeability();
Notes


[edit] GetWeatherType

public native int GetWeatherType(void)
Parameters
  • None
Returned Value
Syntax
int weather = World.GetWeatherType();
Notes


[edit] IsAssetRestrictionInEffect

public native bool IsAssetRestrictionInEffect(string)
Parameters
  • None
Returned Value
  • Whether this game world has Asset Restrictions.
Syntax
bool assetRestrictionsExist = World.IsAssetRestrictionInEffect();
Notes
  • Multiplayer Sessions require Asset Restrictions to be in effect to avoid compatibility issues between peers.
  • Added in ...?


[edit] IsLayerVisible

public native bool IsLayerVisible(string layerName)
Parameter
  • layerName = Name of the layer to check
Returned Value
  • Whether the layer is visible
Syntax
bool isVisible = World.IsLayerVisible("MyLayer");
Notes
  • Added in ...?


[edit] LoadMap

public native bool LoadMap(KUID kuid)
Parameters
  • kuid = KUID of map to load.
Returned Value
  • True if successful, false otherwise.
Syntax
if (World.LoadMap(mapKUID) Interface.Print("Map loaded OK");
else Interface.Print("Map load failed");
Notes
  • Use World.FindKUID() to find the desired route KUID.
  • In multiplayer, this will only succeed on the server.


[edit] LoadSession

public native bool LoadSession(KUID kuid)
Parameters
  • kuid = KUID of session to load.
Returned Value
  • True if successful, false otherwise.
Syntax
if (World.LoadSession(sessionKUID) Interface.Print("Session loaded OK");
else Interface.Print("Session load failed");
Notes
  • Use World.FindKUID() to find the desired session KUID.
  • In multiplayer, this will only succeed on the server.
  • Added in ...?


[edit] Play2DSound

public float Play2DSound(Asset asset, string wave)
Parameters
  • asset = Asset where the sound file is located.
  • wave = Name of the *.wav file to be played, a relative path can be included.
Returned Value
  • Undefined.
Syntax
// Play the sound and continues script execution.
   World.Play2DSound(soundAsset,"sounds/allaboard.wav");        
// Wait until sound has completed before continuing (pre-TS12 only!)
   Sleep(World.Play2DSound(soundAsset,"sounds/allaboard.wav")); 
Notes
  • Plays a .wav" sound file from the given asset's folder.
  • The sound is non directional and can be mono or stereo.
  • This method does not return after the sound has finished playing, it returns with the length of the sound as soon as it is called.
  • This means your code will keep on executing while Trainz is playing the sound.


[edit] PlaySound

public native float PlaySound
    (Asset asset, string wave, float vol, float near, float far, GameObject target, string pt)
    (Asset asset, string wave, float vol, float near, float far, GameObject target, string pt, bool loop)
Parameters
  • asset = Asset where the sound file is located.
  • wave = Name of the *.wav file to be played, a relative path can be included.
  • vol = Volume level to play the sound at (0 to 1)<- These values taken from TRS2019 world.gs file comments
  • near = Distance from the target asset at which the sound will be played at maximum volume.
  • far = Distance from the target asset at which the sound will become inaudible.
  • target = GameObject to which the sound will be attached if a 3d sound is required, null for 2D.
  • pt = Name of attachment point in the target object if a 3d sound is required, null for 2D.
  • loop = (Optional) If true the sound will loop continuously.
Returned Value
  • Sound length in seconds for Trainz before TS12
  • Undefined for TS12 and TANE
Syntax
// Play the sound and continues script execution.
   World.PlaySound(soundAsset,"sounds/allaboard.wav",1.0,10.0,100.0,Station,"a.loudspeaker");     
// Wait until sound has completed before continuing (pre-TS12 only!)
   Sleep(World.PlaySound(soundAsset,"sounds/allaboard.wav",1000.0,10.0,100.0,Station,"a.loudspeaker");     
Notes
  • Plays a .wav sound file from the given asset's folder.
  • If the sound is to be directional a mono sound file is required.
  • This method does not return after the sound has finished playing: it returns as soon as it is called.
  • This means your code will keep on executing while Trainz is playing the sound.
  • If you want to wait for the sound to complete playing before moving on, wrap the PlaySound() call up in a Sleep() call. Note! This works only in Trainz versions before TS12. For newer versions, TS12 and TANE, you can hard-code the duration of the sound, or store it in the extensions container of the config.txt file.
  • The sound volume will be at a maximum for a camera position at or less than the value of the near parameter and will reduce with distance until the hearing position reaches far, when the sound will be inaudible.


[edit] RemoveDriverCharacter

public native void RemoveDriverCharacter(DriverCharacter driver)
Parameters
  • driver = DriverCharacter to remove.
Returned Value
  • None
Syntax
World.RemoveDriverCharacter(dave);
Notes
  • In multiplayer, this will only succeed on the server.


[edit] RemoveDriverCommand

public native void RemoveDriverCommand(DriverCommand command)
Parameters
  • command = DriverCommand to remove.
Returned Value
  • None
Syntax
World.RemoveDriverCommand(driverCommand);
Notes
  • In multiplayer, this will only succeed on the server.


[edit] RestartSession

public native bool RestartSession()
Parameters
Returned Value
  • True if successful, false otherwise.
Syntax
World.RestartSession();
Notes
  • Valid in Driver mode only.
  • In multiplayer, this will only succeed on the server.


[edit] SetBadWeatherFog

public obsolete native void SetBadWeatherFog(float distance)
Parameters
  • distance = Bad weather fog distance to set.
Returned Value
  • None
Syntax
World.SetBadWeatherFog(0.5);
Notes
  • Obsolete in TRS19


[edit] SetCamera

public native bool SetCamera(MapObject focus)
public native void SetCamera(Junction focus)
public native void SetCamera(Vehicle focus, int cameraMode)
public native void SetCamera(Train focus, int cameraMode)
Parameters
  • focus = Object on which the camera is to be focused.
  • cameraMode' = One of the Camera View Mode constants defining the view which should be assigned to the camera.
Returned Value
  • The first variant returns a boolean to indicate success or failure.
  • Remaining variants do not return a value
Syntax
World.SetCamera(train.GetVehicles[0],World.CAMERA_TRACKING); // sets the camera to track the first vehicle in the train.
Notes
  • Junction alias removed in TRS19?


[edit] SetCameraAngle

public void SetCameraAngle(float yaw, float pitch, float radius)
public obsolete void SetCameraAngle(int yaw, int pitch, float radius)
Parameters
  • yaw = Camera rotation in radians (float) or degrees (int), 90 is a direct front view.
  • pitch = Camera angle relative to the horizon in radians (float), or degrees (int), 0 is horizontal, 90 points vertically upwards.
  • radius = Distance in metres to the object in focus.
Returned Value
  • None
Syntax
World.SetCameraAngle(90,0,25); // Sets the camera to a direct frontal view at 25 metres from the currently focused object.
Notes
  • Radius is measured from the object origin point (0,0,0). If there's no target object this will be the distance to the ground.
  • Note difference in units of yaw and pitch depending in the method signature used.
  • The integer version of this method call is obsolete in TRS19.


[edit] SetCameraFlags

public native void SetCameraFlags(int flags)
Parameter
  • flags integer value defining what the user is permitted to do with the game camera.
Returned Value
  • None
Syntax
// User is permitted to select External or Tracking views only.
   World.SetCameraFlags(World.CAMERA_EXTERNAL | World.CAMERA_TRACKING);
Notes


[edit] SetCameraMode

public void SetCameraMode(int mode)
Parameter
  • mode = Camera mode to select.
Returned Value
  • None
Syntax
World.SetCameraMode(World.CAMERA_TRACKING);
Notes


[edit] SetEditingCamera

public void SetEditingCamera(GameObject actor, bool bIsActorEditingCamera)
Parameter
  • actor = The script who is intended to edit the camera position.
  • bIsActorEditingCamera = True to begin editing, or False to end the editing operation.
Returned Value
  • None
Syntax
World.SetEditingCamera(myScript, true);
Notes
  • Hints to the caching systems that the camera position is in the process of being changed. This may reduce the amount of streaming that will occur until the change is complete.
  • This is intended for use-cases where the decision to move the camera happens in advance of the actual call to SetCamera() or etc., for example when the new camera target needs to be streamed in first.
  • There is no advantage in calling this unless your code then sleeps/waits before undoing the call.
  • It is not required to call this before using SetCamera() etc.
  • A boolean state is stored per actor; multiple calls to enable editing on a single actor do not need to be matched to multiple calls to disable editing.
  • It is counterproductive to call this when transitioning the camera over a short distance (ie. where the source and target locations can see each other). If jumping to a new location, followed by a visual camera transition at the new location, camera editing may be enabled around the target-selection for the jump, and the jump itself, but should be disabled before proceeding with the transition.
  • Added in TRS19?


[edit] SetGameDate

public void SetGameDate(int year, int month, int date)
Parameters
  • year = The year to set (1970-2038)
  • month = The month to set (1-12)
  • day = The day to set (1-31)
Returned Value
  • None
Syntax
World.SetGameDate(2000, 12, 25);  // sets date to 25 December 2000
Notes
  • In multiplayer, this will only succeed on the server.
  • Added in ...?


[edit] SetGameTime

public void SetGameTime(float time)
Parameters
  • time = new gane time to set.
Returned Value
  • None
Syntax
World.SetGameTime(0.5);  // sets time to midnight
Notes
  • Game time is normalised to a value between 0.0 and 1.0
  • 0.0 = midday
  • 0.25 = 6 p.m.
  • 0.5 = midnight
  • 0.75 = 6 a.m.
  • 1.0 = midday again
  • Use the Time Value constants to convert human readable times to normalised values.


[edit] SetGameTimeRate

public native void SetGameTimeRate(float rate)
Parameters
  • rate = New time rate to set.
Returned Value
  • None
Syntax
World.SetGameTimeRate(World.TIME_RATE_8X); // sets game time to advance by 8 minutes per minute of real world time.
Notes
  • Use one of the Time Rate Constants to define the parameter.
  • In multiplayer, this will only succeed on the server.


[edit] SetGoodWeatherFog

public obsolete native void SetGoodWeatherFog(float distance)
Parameters
  • distance = Good weather fog distance to set.
Returned Value
  • None
Syntax
World.SetGoodWeatherFog(0.5);
Notes
  • Obsolete in TRS19


[edit] SetGroundDrawDistance

public obsolete native void SetGroundDrawDistance(float distance)
Parameters
  • distance = Ground draw distance in metres.
Returned Value
  • None
Syntax
World.SetGroundDrawDistance(1000.0);
Notes
  • Compatibility warning: Use of this function is not recommended, it may become non-functional in future Trainz versions.


[edit] SetLayerVisible

public native void IsLayerVisible(string layerName, bool visible)
Parameter
  • layerName = Name of the layer to check
  • visible = Whether to set the layer visible or not
Returned Value
  • None
Syntax
World.IsLayerVisible("MyLayer", False);
Notes
  • Show/Hide a route/session layer.
  • In multiplayer, this will only succeed on the server.
  • Added in ...?


[edit] SetSceneryDrawDistance

public obsolete native void SetSceneryDrawDistance(float distance)
Parameters
  • distance = unused.
Returned Value
  • None
Notes
  • Does nothing. Included for script compatibility only.


[edit] SetTargetObserver

public void SetTargetObserver(GameObject observer)
Parameters
  • observer = The game object to receive targeting messages.
Returned Value
  • None
Syntax
SetTargetObserver(self);
Notes
  • It is unlikely a script programmer would ever need to use this method.
  • Causes the specified object to receive "Track", "LeftClick" messages when a track is clicked. Causes the specified object to receive "Interface-Event", "Left-Click" messages when a targetable MapObject is clicked. May cause the functionality of a left mouse click to change from what the user is expecting, so should be used with caution. Used in modal scripts to allow the user to indicate a location for train placement, etc. As there is only a single observer at any given time, the script must take care to only call this function when entering placement mode at the user's request.


[edit] SetWeather

public native void SetWeather(int type, int changeability)
Parameters
Returned Value
  • None
Syntax
World.SetWeather(World.WEATHER_TYPE_HEAVY_SNOW,World.WEATHER_CHANGEABILITY_EXTREME); // April in Paris.
Notes


[edit] SetWorldEditModeEnabled

public native bool SetWorldEditModeEnabled(int editFlags, bool enable)
Parameters
  • editFlags = Bitmask specifying which modes to alter, see PERMIT_EDIT_*
  • cameraMode' = Whether to enable or disable the mode
Returned Value
  • Whether the change was completely successful
Syntax
World.SetWorldEditModeEnabled(World.PERMIT_EDIT_TRAINS | World.PERMIT_EDIT_CONSISTS, True); // Enable player editing of trains and consists
Notes
  • This does not affect scripts which may alter the world, only the availability of the player world editing tools (i.e, the Surveyor tabs).
  • Added in TRS19?


[edit] SynchronouslyLoadGameObjectByID

public GameObject SynchronouslyLoadGameObjectByID(GameObjectID objectID)
Parameters
  • objectID = The ID of the object to find.
Returned Value
  • The object, if it exists.
Syntax
GameObject my_object = World.SynchronouslyLoadGameObjectByID(objectID);
if (my_object Interface.Print("Object exists and has been loaded if required");
Notes
  • This function is usable only by script 'thread' functions and will throw an exception if called incorrectly.
  • Added in TRS19


[edit] UpdatePositionToGroundHeight

public native bool UpdatePositionToGroundHeight(WorldCoordinate position)
Parameters
  • position (in, out) = Position object to update with the ground height at it's location
Returned Value
  • True if the ground position was updated
Syntax
if (World.UpdatePositionToGroundHeight(position) Interface.Print("Position was updated");
Notes
  • This updates the input position object with the ground height at that location.
  • This process may fail if the ground data at the specified location is not currently loaded.
  • Added in TRS19?


[edit] UpdatePositionToSurfaceHeight

public native bool UpdatePositionToSurfaceHeight(WorldCoordinate position)
Parameters
  • position (in, out) = Position object to update with the water height at it's location
Returned Value
  • True if the ground position was updated
Syntax
if (World.UpdatePositionToGroundHeight(position) Interface.Print("Position was updated");
Notes
  • This updates the input position object with the water height at that location. If no water is present, the position is adjusted to the ground height.
  • This process may fail if the ground data at the specified location is not currently loaded.
  • Added in TRS19?


[edit] UserSetCamera

public native bool UserSetCamera(GameObject target)
Parameters
  • target = GameObject to set focus to.
Returned Value
  • True if successful, false otherwise.
Syntax
World.UserSetCamera(Router,GetGameObject("Junction 5"));
Notes


[edit] UserSetCameraMode

public native void UserSetCameraMode(int mode)
Parameters
Returned Value
  • None
Syntax
World.UserSetCameraMode(World.CAMERA_ROAMING);  // switches to roaming view if permitted.
Notes
  • This method respects the current Camera Flag settings, disallowing any change which the flags do not permit.


[edit] UserSetCameraPosition

public native bool UserSetCamera(WorldCoordinate camPos)
Parameters
  • camPos = World coordinates to set camera to
Returned Value
  • True if successful, false otherwise.
Syntax
World.UserSetCamera(Router,GetGameObject("Junction 5"));
Notes
  • For camera modes which do not need to target specific objects, this allows the camera to be set to an arbitrary world position.
  • Added in TRS19?


[edit] Categories

Personal tools