Class Cabin

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
(modified UserPressKey)
m (Reverted edits by Vvmm (talk) to last revision by Windwalkr)
Line 110: Line 110:
 
<br>
 
<br>
  
===UserPressKey===
+
===UserKeyPress===
{{MethodHeader|public void UserPressKey(string s)}}
+
{{MethodHeader|public void UserKeyPress(string keyName)}}
 
;Parameters
 
;Parameters
*'''s''' = The name of the key pressed, as it is found in [[keyboard.txt]]
+
*'''keyName''' = The name of the key pressed.
 
;Returned Value
 
;Returned Value
 
*None
 
*None

Revision as of 14:10, 20 August 2013


  • 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

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.


FireAddCoal

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


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


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


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


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


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


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.


UserKeyPress

public void UserKeyPress(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.


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.


Related Methods


Categories

Personal tools