User talk:Pcas1986

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
(Page development only)
 
(Replaced content with " test space only")
 
Line 1: Line 1:
These are examples of solutions for common and simple obsolete Trainzscript functions. This is not an exhaustive list.  Solutions for more complex obsolete functions can be found (TBD).
+
  test space only
 
+
=class Train=
+
 
+
==GetVelocity()==
+
 
+
GetVelocity obsolete error or warning: <kuid:0000:0000> : VE267: somescript.gs(299) : function GetVelocity is obsolete in object Train.
+
 
+
 
+
'''Repair'''
+
 
+
You have two replacement options in the Train class (train.gs):
+
 
+
 
+
''float GetSmoothedVelocity(void);''
+
 
+
This function return the train's velocity in metres per second and is suitable for human viewing such as a cab display.
+
 
+
 
+
''float GetTrainVelocity(void);''
+
 
+
This function provides the instantaneous velocity for vehicles in this train, which is good for physics calculations but not good for human-readable display.<br><br>
+
+
'''Usage example:'''
+
 
+
float mySpeed;
+
mySpeed = GetSmoothedVelocity();  // this is the more likely option but depends on what the overall script is trying to do.
+
+
// or the more accurate version
+
mySpeed = GetTrainVelocity();
+
+
=class Vehicle=
+
 
+
==GetFacingRelativeToTrain()==
+
 
+
???GetFacingRelativeToTrain obsolete error or warning: <kuid:0000:0000> : VE267: somescript.gs(450) : function GetFacingRelativeToTrain is obsolete in object Vehicle.
+
 
+
 
+
'''Repair'''
+
 
+
You have one replacement option in the Vehicle class (vehicle.gs):
+
 
+
 
+
''bool GetDirectionRelativeToTrain(void);''
+
 
+
This function returns true if the vehicle faces the same way as the Train, false otherwise.  This function is a bit tricky to understand and especially when a vehicle, such as a coach/carriage, is involved.
+
+
'''Usage example1:'''
+
 
+
Vehicle myVehicle;
+
bool sameDirectionAsTrain;
+
+
sameDirectionAsTrain = GetDirectionRelativeToTrain(); 
+
+
'''Usage example2:'''
+
 
+
Vehicle[] trainVehicles;
+
Vehicle myVehicle;
+
bool sameDirectionAsTrain;
+
int i;
+
+
trainVehicles = GetMyTrain().GetVehicles();
+
+
if (trainVehicles) {  //unlikely to be null but ...
+
+
  for (i = 0; i < trainVehicles.size(); ++i) {
+
    //get direction of this vehicle in the train
+
    sameDirectionAsTrain = trainVehicles[i].GetDirectionRelativeToTrain();
+
    if (sameDirectionAsTrain) {
+
      // do what is necessary here
+
      Interface.Print("Vehicle "+ (i+1) + " is facing forward");  // add 1 so that the first vehicle is number 1 and not 0 (zero)
+
    } else {
+
      Interface.Print("Vehicle "+ (i+1) + " is facing backwards");
+
    }
+
  }
+
+
}
+

Latest revision as of 13:08, 26 August 2022

test space only
Personal tools