Class World
From TrainzOnline
(Difference between revisions)
m (→CreateTrain: Fix formatting) |
(→GetNamedObjectList) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 554: | Line 554: | ||
;Syntax | ;Syntax | ||
GameObject my_object = World.GetGameObjectByID(objectID); | GameObject my_object = World.GetGameObjectByID(objectID); | ||
− | if (my_object Interface.Print("Object exists and is loaded"); | + | if (my_object) Interface.Print("Object exists and is loaded"); |
;Notes | ;Notes | ||
*Added in TRS19 | *Added in TRS19 | ||
Line 718: | Line 718: | ||
*When the search completes, a message of type "ObjectSearch","AsyncResult" will be posted to the result object. | *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. | *With expiration notices are enabled, only one notification of type "ObjectSearch","Expired" will be posted for each search. | ||
− | *Added in TRS19 | + | *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> | <br> | ||
Line 1,130: | Line 1,131: | ||
==SetGameDate== | ==SetGameDate== | ||
− | {{MethodHeader|public void | + | {{MethodHeader|public void SetGameDate(int year, int month, int date)}} |
;Parameters | ;Parameters | ||
*'''year''' = The year to set (1970-2038) | *'''year''' = The year to set (1970-2038) | ||
Line 1,138: | Line 1,139: | ||
*None | *None | ||
;Syntax | ;Syntax | ||
− | World. | + | World.SetGameDate(2000, 12, 25); // sets date to 25 December 2000 |
;Notes | ;Notes | ||
*In multiplayer, this will only succeed on the server. | *In multiplayer, this will only succeed on the server. |
Latest revision as of 01:42, 30 July 2022
- API Hierarchy
- World (world.gs)
- World is a static class used to access various aspects of the Trainz environment.
[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
- These constants can be used for querying route/session layers via GetLayerList and GetLayerType.
- Added in TRS19?
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
- These constants can be used to set editing modes through World.SetWorldEditModeEnabled().
- Added in TRS19?
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
- 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)
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
- 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
- Is this value equivalent to radius in SetCameraAngle()?
- Added in ...?
[edit] GetCurrentModule
public native int GetCurrentModule(void)
- Parameters
- None
- Returned Value
- An integer representing the current Trainz module.
- Syntax
int module = World.GetCurrentModule();
- Notes
- See Trainz Modules for details of the constants associated with this method.
- See ModuleInit Message for further details.
[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)
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
- This function is obsolete and should not be used. Use GetNamedObjectList instead.
[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
- 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)
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
- This function is obsolete and should not be used. Use GetNamedObjectList instead.
[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
- This function is obsolete and should not be used. Use GetNamedObjectList instead.
[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
- This function is obsolete and should not be used. Use GetNamedObjectList instead.
[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
- This function is obsolete and should not be used. Use GetNamedObjectList instead.
[edit] GetWeatherChangeability
public native int GetWeatherChangeability(void)
- Parameters
- None
- Returned Value
- One of the Weather Changeability Constants denoting the variability of weather conditions.
- Syntax
int variability = World.GetWeatherChangeability();
- Notes
[edit] GetWeatherType
public native int GetWeatherType(void)
- Parameters
- None
- Returned Value
- One of the Weather Type Constants denoting the current weather conditions.
- 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)
(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)
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)
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
- Use any combination of Camera Flags and Camera View Modes to set the parameter.
[edit] SetCameraMode
public void SetCameraMode(int mode)
- Parameter
- mode = Camera mode to select.
- Returned Value
- None
- Syntax
World.SetCameraMode(World.CAMERA_TRACKING);
- Notes
- Use one of the Camera View Modes to set the parameter.
[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
- type = Weather conditions as defined by one of the Weather Type Constants.
- change = Weather variation as defined by one of the Weather Changeability Constants.
- 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
- mode = One of the Camera View Modes
- 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?