HowTo/Upgrade obsolete script functions - simple examples
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).
Under Development The contents and the layout of this page is under development.
Contents |
class Crossing
SetCrossingAutomatic()
SetCrossingState()
Error: VE197: Syntax error in script 'somescript.gs' for asset <kuid:0000:0000> "Asset Name".
Error: VE267: somescript.gs(48) : function SetCrossingAutomatic is obsolete in object Crossing.
Error: VE267: somescript.gs(48) : function SetCrossingState is obsolete in object Crossing.
This method now requires a SecrityToken as a parameter to the function call
Repair
You need to initialize a SecurityToken, then add it as a parameter to your function calls.
Usage example:
In your header add
SecurityToken stoken;
Then in your function calls add your token.
SetCrossingAutomatic(stoken, false); SetCrossingState(stoken, 1);
More information on Class Crossing
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.
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"); } } }