HowTo/Upgrade obsolete script functions - simple examples

From TrainzOnline
< HowTo
Revision as of 15:41, 13 September 2022 by Pcas1986 (Talk | contribs)

Jump to: navigation, search

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 SecurityToken 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 HTMLWindow

GetCompleteIndustryViewDetailsHTMLCode()

VE267: somescript.gs(linenumber) : function GetCompleteIndustryViewDetailsHTMLCode is obsolete in object HTMLWindow.

This error occurs when trying to use this method with an obsolete class. In this case, class GenericIndustry has been obsoleted and replaced with BaseIndustry.

Repair

Change all instances of 'GenericIndustry' in the code to 'BaseIndustry'.

Usage example:

include "BaseIndustry.gs"
class <myclass> isclass BaseIndustry>

class IndustryProductInfoCollection

GetProductIndexFromAsset()

<kuid2:00000:00000:1> : VE267: multipleindustryplus.gs(711) : function GetProductIndexFromAsset is obsolete in object IndustryProductInfoCollection.

Repair

Replace with GetProductIndex(Asset product) from the same class. The returned value (int) is the same.

GetProcessIndexFromName()

 <kuid2:00000:00000:1> : VE267: multipleindustryplus.gs(2024) : function GetProcessIndexFromName is obsolete in object IndustryProductInfoCollection.

Repair Replace with GetProcessIndex(int productIndex, string processName) from the same class. The returned value (int) is the same.

AddProduct()

 <kuid2:00000:00000:1> : VE267: somescript.gs(999) : function AddProduct(string, string) is obsolete in object IndustryProductInfoCollection.

Repair Replace with AddProduct(Asset product, Vehicle vehicle) from the same class. Instead of using strings for product and vehicle names, you will need to provide a product asset and a vehicle of type Vehicle.

Usage example: TBD

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"); 
    }
  }

}
Personal tools