Class TrainUtil

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
(rv one edit to Revision as of 11:42, 2010 February 9 by Windwalkr, {{ORP}} tagging inappropriate in category:Script Class pages, {TOCright} clashes with format as well.)
m (Add reference links to other classes)
Line 21: Line 21:
  
 
==AreInTrain==
 
==AreInTrain==
{{MethodHeader|public bool AreInTrain(Train train, Vehicle[ ] vehicles)}}
+
{{MethodHeader|public bool AreInTrain([[Class Train|Train]] train, [[Class Vehicle|Vehicle]][ ] vehicles)}}
 
;Parameters
 
;Parameters
 
*'''train''' = Train to search.
 
*'''train''' = Train to search.
Line 45: Line 45:
  
 
==CreateTrainFromSoup==
 
==CreateTrainFromSoup==
{{MethodHeader|public Train CreateTrainFromSoup(Soup trainSoup, string trackmarkName, bool direction)}}
+
{{MethodHeader|public [[Class Train|Train]] CreateTrainFromSoup([[Class Soup|Soup]] trainSoup, string trackmarkName, bool direction)}}
 
;Parameters
 
;Parameters
 
*'''trainSoup''' = Consist definition in the form returned by [[Class World#GetSurveyorSavedConsist|World.GetSurveyorSavedConsist()]].
 
*'''trainSoup''' = Consist definition in the form returned by [[Class World#GetSurveyorSavedConsist|World.GetSurveyorSavedConsist()]].
Line 59: Line 59:
  
 
==DoCoupleUp==
 
==DoCoupleUp==
{{MethodHeader|public Train DoCoupleUp(Train train, Train coupleTo)}}
+
{{MethodHeader|public [[Class Train|Train]] DoCoupleUp([[Class Train|Train]] train, [[Class Train|Train]] coupleTo)}}
 
*'''train''' = First train.
 
*'''train''' = First train.
 
*'''coupleTo''' = Train to couple with.
 
*'''coupleTo''' = Train to couple with.
Line 70: Line 70:
  
 
==DoDecouple==
 
==DoDecouple==
{{MethodHeader|public Train DoDecouple(Train train, int count)}}
+
{{MethodHeader|public [[Class Train|Train]] DoDecouple([[Class Train|Train]] train, int count)}}
 
;Parameters
 
;Parameters
 
*'''train''' = Train reference.
 
*'''train''' = Train reference.
Line 139: Line 139:
  
 
==IsInTrain==
 
==IsInTrain==
{{MethodHeader|public bool IsInTrain(Train train, Vehicle vehicle)}}
+
{{MethodHeader|public bool IsInTrain([[Class Train|Train]] train, [[Class Vehicle|Vehicle]] vehicle)}}
 
;Parameters
 
;Parameters
 
*'''train''' = Train reference.
 
*'''train''' = Train reference.
Line 152: Line 152:
  
 
==IsPartTrainInTrigger==
 
==IsPartTrainInTrigger==
{{MethodHeader|public bool IsPartTrainInTrigger(GameObject runningThread, Train train, Trigger trigger)}}
+
{{MethodHeader|public bool IsPartTrainInTrigger([[Class GameObject|GameObject]] runningThread, [[Class Train|Train]] train, [[Class Trigger|Trigger]] trigger)}}
 
;Parameters
 
;Parameters
 
*'''runningThread''' = Thread that called this method.
 
*'''runningThread''' = Thread that called this method.
Line 165: Line 165:
  
 
==IsTrainInTrigger==
 
==IsTrainInTrigger==
{{MethodHeader|public bool IsTrainInTrigger(GameObject runningThread, Train train, Trigger trigger)}}
+
{{MethodHeader|public bool IsTrainInTrigger([[Class GameObject|GameObject]] runningThread, [[Class Train|Train]] train, [[Class Trigger|Trigger]] trigger)}}
 
;Parameters
 
;Parameters
 
*'''runningThread''' = Thread that called this method.
 
*'''runningThread''' = Thread that called this method.
Line 190: Line 190:
 
==RunTurnTable==
 
==RunTurnTable==
 
<font color=red>Is this still valid?</font>
 
<font color=red>Is this still valid?</font>
{{MethodHeader|public void RunTurnTable(GameObject runningThread, Train train, string turntable)}}
+
{{MethodHeader|public void RunTurnTable([[Class GameObject|GameObject]] runningThread, [[Class Train|Train]] train, string turntable)}}
 
*'''runningThread''' = Thread that called this method.
 
*'''runningThread''' = Thread that called this method.
 
*'''train''' = Reference to a train.
 
*'''train''' = Reference to a train.
Line 221: Line 221:
 
==WaitUntilHas==
 
==WaitUntilHas==
 
<font color=red>Is this still valid?</font>
 
<font color=red>Is this still valid?</font>
{{MethodHeader|public void WaitUntilHas(Vehicle loco, ShuntTrack tracking)}}
+
{{MethodHeader|public void WaitUntilHas([[Class Vehicle|Vehicle]] loco, ShuntTrack tracking)}}
 
;Parameters
 
;Parameters
 
*'''loco''' = Consist locomotive.
 
*'''loco''' = Consist locomotive.

Revision as of 00:57, 29 December 2020


  • TrainUtil is a static utility class containing a miscellany of methods.


Contents

AlreadyThereStr

public bool AlreadyThereStr(string[ ] target, string search)
Parameters
  • target = Array of strings to search.
  • search = String to look for.
Returned Value
  • Boolean indicating whether or not the string search exists in the target array.
Syntax
string[] target = Str.Tokens("one two three");
bool found = TrainUtil.AlreadyThereStr(target,"four");    // the result will be false
Notes
  • As is usual in Trainzscript string methods the search is case sensitive.


AreInTrain

public bool AreInTrain(Train train, Vehicle[ ] vehicles)
Parameters
  • train = Train to search.
  • vehicles = Array of vehicle to look for.
Returned Value
  • True if all of the vehicles in the array are found in the train, false otherwise.
Syntax
bool allPresent = TrainUtil.AreInTrain(train,vehicles);
Notes


CompareStrLists

public bool CompareStrLists(string[ ] list1, string[ ] list2)
Parameters
  • list1,list2 = String arrays.
Returned Value
  • True if the lists are identical, same strings in each index position, same total count. False otherwise.
Syntax
bool identical = TrainUtil.CompareStrLists(address1,address2);
Notes


CreateTrainFromSoup

public Train CreateTrainFromSoup(Soup trainSoup, string trackmarkName, bool direction)
Parameters
  • trainSoup = Consist definition in the form returned by World.GetSurveyorSavedConsist().
  • trackmarkName = Name of the trackmark where the train is to be placed.
  • direction = True denotes that the train direction should match that of the trackmark.
Returned Value
  • A reference to the newly created train if successful, null otherwise.
Syntax
Train train = TrainUtil.CreateTrainFromSoup(BrightonBelle,"Victoria Station",true);
Notes
  • It is the script programmer's responibility to ensure that sufficient track exists.


DoCoupleUp

public Train DoCoupleUp(Train train, Train coupleTo)
  • train = First train.
  • coupleTo = Train to couple with.
Returned Value
  • A reference to the newly extended train.
Syntax
Train newTrain = TrainUtil.DoCoupleUp(train, newSection);
Notes


DoDecouple

public Train DoDecouple(Train train, int count)
Parameters
  • train = Train reference.
  • count = Number of wagons to detach from the rear of the train.
Returned Value
  • A reference to the remaining consist (front section) if successful, null otherwise.
Syntax
train = TrainUtil.DoDecouple(train,4);  // drop four cars from the rear of the train, train will be null if this fails.
Notes
  • It is assumed that the train is stopped and already in position.
  • The method will wait for the operation to be completed.


GetAfter

public string GetAfter(string target, string search)
Parameters
  • target = String to operate on.
  • search = String containing delimiter characters.
Returned Value
  • Substring of target to the right of the characters in search.
Syntax
string result = TrainUtil.GetAfter("Afternoon", "er");   // result is "noon"
Notes
  • The method starts at the end of the string and works backwards until any of the characters in search are encountered.
  • Once any character in search is found the substring after that character is returned.
  • If search is not found the result will be an empty string.


GetUpTo

public string GetUpTo(string target, string search)
Parameters
  • target = String to operate on.
  • search = String containing delimiter characters.
Returned Value
  • Substring of target to the left of the characters in search.
Syntax
string result = TrainUtil.GetUpTo("Before noon"," no");   // result is "Before"
Notes
  • The method starts at the beginning of the string and works forwards until any of the characters in search are encountered.
  • Once any character in search is found the substring before that character is returned.
  • If search is not found the result will be an empty string.


HasPrefix

public bool HasPrefix(string target, string prefix)
Parameters
  • target = String to operate on.
  • prefix = String containing prefix to search for.
Returned Value
  • True if target starts with prefix, false otherwise.
Syntax
bool IsPrefixed = TrainUtil.HasPrefix("ante","antecedent"); // returns true
Notes


HasSufix

public bool HasSufix(string target, string suffix)
Parameters
  • target = String to operate on.
  • suffix = String containing suffix to search for.
Returned Value
  • True if target ends with suffix, false otherwise.
Syntax
bool IsSuffixed = TrainUtil.HasSufix("dent","antecedent"); // returns true
Notes
  • This will not work if the method identifier is correctly spelled!


IsInTrain

public bool IsInTrain(Train train, Vehicle vehicle)
Parameters
  • train = Train reference.
  • vehicle = Vehicle reference.
Returned Value
  • True if vehicle is included in train, false otherwise.
Syntax
bool brakeVanPresent = TrainUtil.IsInTrain(train,brakeVan); 
Notes


IsPartTrainInTrigger

public bool IsPartTrainInTrigger(GameObject runningThread, Train train, Trigger trigger)
Parameters
  • runningThread = Thread that called this method.
  • train = Reference to a train.
  • trigger = Reference to the trigger to query.
Returned Value
  • True if any part of the train is in the trigger area, false otherwise.
Syntax
bool arrived = TrainUtil.IsPartTrainInTrigger(me,train,trigger);
Notes


IsTrainInTrigger

public bool IsTrainInTrigger(GameObject runningThread, Train train, Trigger trigger)
Parameters
  • runningThread = Thread that called this method.
  • train = Reference to a train.
  • trigger = Reference to the trigger to query.
Returned Value
  • True if the train is in the trigger area, false otherwise.
Syntax
bool arrived = TrainUtil.IsTrainInTrigger(me,train,trigger);
Notes


RandBool

public bool RandBool(void)
Parameters
  • None
Returned Value
  • True or false at random.
Syntax
if(TrainUtil.RandBool()) DoItAtRandom();
Notes


RunTurnTable

Is this still valid?

public void RunTurnTable(GameObject runningThread, Train train, string turntable)
  • runningThread = Thread that called this method.
  • train = Reference to a train.
  • turntable = Name of turntable.
Returned Value
  • None
Syntax
TrainUtil.RunTurnTable(me,train,"Turntabel 1");
Notes
  • ???????


StrSubst

public string StrSubst(string target, string remove, string replace)
Parameters
  • target = String to operate on.
  • remove = Substring to remove.
  • replace = Replacement substring.
Returned Value
  • Returns the string target with replace substituted for remove, if the method fails an empty string is returned.
Syntax
string s = "Gnomes are your friends";
s = TrainUtil.StrSubst(s,"friends","enemies");    // returns "Gnomes are your enemies"
Notes
  • remove must exist as a substring of target, otherwise and empty string will be returned.
  • remove and replace do not have to be the same length.
  • Only the first instance of remove will be substituted.


WaitUntilHas

Is this still valid?

public void WaitUntilHas(Vehicle loco, ShuntTrack tracking)
Parameters
  • loco = Consist locomotive.
  • tracking = Tracking array.
Returned Value
  • None
Syntax
Notes
  • Waits until all of the vehicles tracked by the tracking array are in the train of the given loco.


Related Methods

Categories

Personal tools