Class Locomotive

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
m
m (Change link to library reference, not language reference)
 
(14 intermediate revisions by 4 users not shown)
Line 1: Line 1:
*[[TrainzScript Language Reference|API Hierarchy]]
+
*[[TrainzScript Library Reference|API Hierarchy]]
 
**[[Class GSObject|GSObject]] *
 
**[[Class GSObject|GSObject]] *
 
***[[Class GameObject|GameObject]]
 
***[[Class GameObject|GameObject]]
Line 41: Line 41:
 
  float throttle = GetEngineSetting("throttle");
 
  float throttle = GetEngineSetting("throttle");
 
;Notes
 
;Notes
*See [[#SetEngienSetting|SetEngineSetting()]] for details of the values which can be used for the ''setting'' parameter.
+
*See [[#SetEngineSetting|SetEngineSetting()]] for details of the values which can be used for the ''setting'' parameter.
 +
<br>
 +
 
 +
===SetBellState===
 +
{{MethodHeader|public native void SetBellState(bool state)}}
 +
;Parameters
 +
*'''state''' = If true plays and loops the sound of a bell, a value of false will deactivation it.
 +
;Returned Value
 +
*None
 +
;Syntax
 +
SetBellState(true);
 +
;Notes
 +
*Asset of kind "hornsound" must be in the locomotive config.
 
<br>
 
<br>
  
Line 51: Line 63:
 
*None
 
*None
 
;Syntax
 
;Syntax
  SetBrokenReverser(ture);  
+
  SetBrokenReverser(true);  
 
;Notes
 
;Notes
 
*When broken the reverser lever can still be used by the player but it will have no effect on the locomotive.
 
*When broken the reverser lever can still be used by the player but it will have no effect on the locomotive.
Line 91: Line 103:
 
  SetCompressorEfficiency(0.5);
 
  SetCompressorEfficiency(0.5);
 
;Notes
 
;Notes
 +
*For a slow increase in pressure of the main reservoir.
 
<br>
 
<br>
  
Line 105: Line 118:
 
*Settings you can write to with this method are:
 
*Settings you can write to with this method are:
 
**"dynamic-brake"
 
**"dynamic-brake"
**"headlight"
+
**"headlight" (value 0,0.5,1 only)
 +
**"horn"
 
**"injector"
 
**"injector"
**"loco-auto-brake"
+
**"loco-auto-brake" (i.e independantbrake_lever)
 
**"pantograph"
 
**"pantograph"
 
**"regulator"
 
**"regulator"
Line 113: Line 127:
 
**"steam-blower"
 
**"steam-blower"
 
**"throttle"
 
**"throttle"
**"train-auto-brake"
+
**"train-auto-brake" (i.e. trainbrake_lever')
 
**"train-lap-brake"
 
**"train-lap-brake"
*These strings correspond to engine properties as described in the Content Creation Guide.
+
**"script-brake-pressure" - A script-only brake pressure which does not correspond to any real brake device, specified in kPa. This may be used by interior scripts for implementing custom cab-mode braking behaviour, and is intended to be directly mapped from the cab controls rather than updated on a regular frame-by-frame basis from script. Native brake controls should be used where possible to avoid significant performance problems.
 
*Some apply to steam locomotives only.
 
*Some apply to steam locomotives only.
 +
*From personal experience: the settings for the electric locomotive are set in whole numbers ("dynamic-brake" 0-1-2; "reverser" 0-1-2 and so on).
 
<br>
 
<br>
  

Latest revision as of 23:42, 28 December 2020


  • A Locomotive is a specialised instance of a vehicle.
  • In practice many of the methods in Class Vehicle apply to powered vehicles.
  • A locomotive is always part of a train, if a locomotive is decoupled and left alone TRS will create a new consist to include it.


Contents

[edit] Methods


[edit] GetCabinData

public CabinData GetCabinData(void)
Parameters
  • None
Returned Value
  • A reference to a data object which stores the state of the locomotive's cabin.
Syntax
MyCabinData = loco.GetCabinData();
Notes
  • See Class CabinData
  • The data object refers to an internal private CabinData object in this class that represents the state of the cabin's controls.
  • This is usually maintained by the Cabin.Attach() and Cabin.Update() methods of the Cabin script.


[edit] GetEngineSetting

public native float GetEngineSetting(string setting)
Parameters
  • setting = The name of the setting to retrieve.
Returned Value
  • The value of the named setting.
Syntax
float throttle = GetEngineSetting("throttle");
Notes
  • See SetEngineSetting() for details of the values which can be used for the setting parameter.


[edit] SetBellState

public native void SetBellState(bool state)
Parameters
  • state = If true plays and loops the sound of a bell, a value of false will deactivation it.
Returned Value
  • None
Syntax
SetBellState(true);
Notes
  • Asset of kind "hornsound" must be in the locomotive config.


[edit] SetBrokenReverser

public native void SetBrokenReverser(bool broken)
Parameters
  • broken = If true the reverser will not function, a value of false will reactivate it.
Returned Value
  • None
Syntax
SetBrokenReverser(true); 
Notes
  • When broken the reverser lever can still be used by the player but it will have no effect on the locomotive.


[edit] SetBrokenThrottle

public native void SetBrokenThrottle(bool broken)
Parameters
  • broken = If true the throttle will not function, a value of false will reactivate it.
Returned Value
  • None
Syntax
SetBrokenThrottle(true);
Notes
  • When broken the throttle lever can still be used by the player but it will have no effect on the locomotive.


[edit] SetCabinData

public void SetCabinData(CabinData data)
Parameters
  • data = A reference to the data object used to store details of the locomotive's cabin controls.
Returned Value
  • None
Syntax
SetCabinData(MyCabinData);
Notes
  • See Class CabinData
  • The data object refers to an internal private CabinData object in this class that represents the state of the cabin's controls.
  • This is usually maintained by the Cabin.Attach() and Cabin.Update() methods of the Cabin script.


[edit] SetCompressorEfficiency

public native void SetCompressorEfficiency(float efficiency)
Parameters
  • efficiency = Efficiency of the compressor in the range 0.0 .. 1.0
Returned Value
  • None
Syntax
SetCompressorEfficiency(0.5);
Notes
  • For a slow increase in pressure of the main reservoir.


[edit] SetEngineSetting

public native void SetEngineSetting(string setting, float value)
Parameters
  • setting = The name of the setting to save.
  • value = The value of the named setting.
Returned Value
  • None
Syntax
SetEngineSetting("regulator",0.5);
Notes
  • Settings you can write to with this method are:
    • "dynamic-brake"
    • "headlight" (value 0,0.5,1 only)
    • "horn"
    • "injector"
    • "loco-auto-brake" (i.e independantbrake_lever)
    • "pantograph"
    • "regulator"
    • "reverser"
    • "steam-blower"
    • "throttle"
    • "train-auto-brake" (i.e. trainbrake_lever')
    • "train-lap-brake"
    • "script-brake-pressure" - A script-only brake pressure which does not correspond to any real brake device, specified in kPa. This may be used by interior scripts for implementing custom cab-mode braking behaviour, and is intended to be directly mapped from the cab controls rather than updated on a regular frame-by-frame basis from script. Native brake controls should be used where possible to avoid significant performance problems.
  • Some apply to steam locomotives only.
  • From personal experience: the settings for the electric locomotive are set in whole numbers ("dynamic-brake" 0-1-2; "reverser" 0-1-2 and so on).


[edit] SetHasDriver

public native void SetHasDriver(bool hasDriver)
Parameters
  • hasDriver = If true the locomotive has an assigned driver, if false it does not.
Returned Value
  • None
Syntax
SetHasDriver(true);
Notes
  • Only one locomotive in a train may have a driver.
  • If you attempt to place a driver in this loco, any other driver on the train will be removed.
  • The consist name and id will always stay with the driver.


[edit] Code Examples


[edit] Related Methods

Train.GetFrontmostLocomotive()
Train.GetVehicles()
World.GetVehicleList()

[edit] Categories

Personal tools