Class Cabin

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
(SetCabLightIntensity)
m (Change link to library reference, not language reference)
 
(One intermediate revision by one user 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 28: Line 28:
 
*A Locomotive object has a cache of cabin control settings that can be saved to when the cabin is updated (see [[Class Locomotive#GetCabinData|Locomotive.GetCabinData()]])
 
*A Locomotive object has a cache of cabin control settings that can be saved to when the cabin is updated (see [[Class Locomotive#GetCabinData|Locomotive.GetCabinData()]])
 
*The programmer will need to update and make use of cabin settings in their implementation of this method.
 
*The programmer will need to update and make use of cabin settings in their implementation of this method.
 +
*This gets called '''after''' the cabin is fully initialized (after the Init function has run successfully). You can not rely on any information from here to be present during the init.
 
<br>
 
<br>
  

Latest revision as of 23:47, 28 December 2020


  • This class is the interface class used for cabins and interior assets in Trainz.
  • From the scripting perspective, a Cabin is mainly a collection of controls.
  • What controls the cabin has depends on the configuration of the asset.
  • If a cabin asset is to have custom scripted features, it's script class will need to be derived from this one.
  • The types of controls a cabin has is locomotive specific hence this class is the interface and not a cabin implementation.
  • The DefaultLocomotiveCabin and DefaultSteamCabin classes provide basic default Cabin implementations.


Contents

[edit] Attach

public void Attach(GameObject owner)
Parameters
  • owner = GameObjet to which the cabin will be attached, normally a Locomotive.
Returned Value
  • None
Notes
  • A callback method used by the game engine when it is about to attach this cabin to an object.
  • A cabin is destroyed when it is no longer needed and re-created by Trainz later on if needed again.
  • This method is where you should restore any saved cabin control settings.
  • A Locomotive object has a cache of cabin control settings that can be saved to when the cabin is updated (see Locomotive.GetCabinData())
  • The programmer will need to update and make use of cabin settings in their implementation of this method.
  • This gets called after the cabin is fully initialized (after the Init function has run successfully). You can not rely on any information from here to be present during the init.


[edit] FireAddCoal

public native bool FireAddCoal(void)
Parameters
  • None
Returned Value
  • True if coal is added successfully, false otherwise.
Syntax
FireAddCoal();
Notes


[edit] GetControls

public native CabinControl[ ] GetControls(void)
Parameters
  • None
Returned Value
  • An array of the CabinControl objects applicable to the cabin.
Syntax
CabinControl[] controls = GetControls();
Notes


[edit] GetNamedControl

public native CabinControl GetNamedControl(string name)
Parameters
  • name = Name of control to return.
Returned Value
  • A reference to the named control if it exists, null otherwise.
Syntax
CabinControl control = GetNamedControl("brake");
Notes


[edit] GetParentObject

public native GameObject GetParentObject(void)
Parameters
  • None
Returned Value
  • A reference to the parent GameObject to which the cabin is attached, usually a Locomotive.
Syntax
Locomotive loco = cast<Locomotive>cabin.GetParentObject();
Notes


[edit] IsActive

public native bool IsActive(void)
Parameters
  • None
Returned Value
  • True if the cabin is currently active, false otherwise.
Syntax
bool cabinExists = cabin.IsActive();
Notes


[edit] SetCabLightIntensity

public native void SetCabLightIntensity(float intensity)
Parameters
  • intensity' = A normalised lighting level in the range 0.0..1.0
Returned Value
  • None
Syntax
SetCabLightIntensity(0.5);
Notes

It works? In build 4.3 no changes are visible. Should the texture glow turn on?

[edit] Update

public void Update(void)
Parameters
  • None
Returned Value
  • None
Notes
  • This is a callback method used by Trainz to update the cabin object.
  • This implementation is empty so the script programmer must implement it if they want their cabin's controls to be updated.
  • If you want to keep the controls in the cabin up to date and to accurately reflect the current state of the locomotive, you will need to perform those updates from an overridden implementation of this method.
  • This is mostly a case of querying the current status of the host locomotive and applying it to the matching control.
  • The speedometer in the cab for instance should be updated based on the loco's current velocity.


[edit] UserPressKey

public void UserPressKey(string keyName)
Parameters
  • keyName = The name of the key pressed.
Returned Value
  • None
Notes
  • This is a callback method used by Trainz when the user presses a key.
  • The default Cabin implementation does not handle any keystrokes. You must do so in your own overridden implementation.


[edit] UserSetControl

public void UserSetControl(CabinControl control, float value)
Parameters
  • control = The control that the user has operated.
  • value = The value to assign as a result of the user's action.
Returned Value
  • None
Notes
  • This is a callback method used by Trainz when the user presses a key.
  • You should override this method to apply the settings selected by the user.


[edit] Related Methods


[edit] Categories

Personal tools