1. How would you write the command line to make your train?
Answer: Using Engine Shed in StopGap by Smileyman.
If you export from CH2 first, when you load StopGap, the consist names are already loaded into the dropdown box of Consist Name in Engine Shed. It will handle all of the code for you. Also, when you create a train using Engine Shed, the name of the train will be added to all of the dropdown boxes that require Train Names, as well as being loaded each time you load that scenario into StopGap.You don't have to remember the name of your train from then on, as it will be just a click away.
2. How does trainz recognize, operate and create your script?
Answer: Explanation by Peter5
When you are building the consist in Consist Helper, or manually, you are not using a train name. You are populating an array of traincars. The name you use, in your case "passenger" is the name of the array. So your consist specification is
// Setup of Consist (passenger)
KUID[] passenger = new KUID[0]; **Name of the kuid array
passenger[0] = World.FindKUID("NS_1600"); ** 1st element is NS_1600
passenger[1] = World.FindKUID("ATSFChairCar"); ** 2nd element is ATSF_Chair
passenger[2] = World.FindKUID("ATSFChairCar"); ** etc.
passenger[3] = World.FindKUID("ATSFChairCar"); ** etc.
Arrays in TrainzScript are zero based so the first element is [0].
Now to create your train you are going to call.
Train passengerTrain = World.CreateTrain(passenger, "trackmark", true or false);
This breaks down as:
"Train" - I am creating a train
"passengerTrain" - I am calling my train passengerTrain (this can be anyname you choose and it is what all other script commands use to communicate with your train.
"World.CreateTrain" - this is calling the CreateTrain method from the World Class. You don't need to know how this works at this point.
"passenger" - Use the cars from my "passenger" array
"trackmark" - place the train on this trackmark on the map (quotes required here)
"true or false" - true means going in the trackmark direction. false means going opposite the trackmark direction.
Anytime you want to send a message to your train you use the train's name. In this case passengerTrain.....
3. Problem posted by LLJ
A train arrives, and the engine decouples.
Another engine couples at the other end and pushes the cars over a hump and uncouple the last car at the crest, trigged by a trigger.
Now to the problem: How do I know the index of the last car?
Depending of direction of the arriving train, the last car is not always the size of the train.GetVehicles().size() .
Is there any clever way to solve this?
Answer: Explanation by Adamsloco
The way that I solved a similar problem is to do this comparison.
Vehicle engine = train.GetFrontMostLocomotive();
if (vehicle[vehicle.size()] == engine)
{
Interface.Log ("This end has an engine on it! Use Vehicle [0] instead")
}
Answer: Explanation by PaulSid
There should be a "- 1" inside the [] up there (sans quotes). array[array.size()] will always be undefined.
4. Question posted by LLJ
I want to declare a KUID array of size 0 in the main thread, pass the array to a function in a class where the array gets another size and are filled with data.
Then I want to use the KUID array to create a Train in the main thread. The problem is that the data is not returned from the function (the size of the KUID array is 1).
Can this be done in TrainzScript?
Answer: Explanation by stationbrace
Yes, but I don't see any use in passing a empty array though. Best to create the array inside the function and return the pointer to it.
5. Question posted by Ish6
Can a trigger detect how many rolling stocks you are hauling?
Answer: Explanation by Paulsid
I can think of two ways to do this:
1) Use coupling masks to control where the train can be decoupled. You can set them on a per-vehicle or per-train basis; in this case of course you want just one vehicle. Roughly, it would look something like this:
Vehicles v[] = train.GetVehicles();
v[size(v)-10].SetDecouplingMask(Vehicle.COUPLE_FRONT);
(The number there is the number of cars you want to remove.) The rest of the time (when a decouple is not imminent) the decoupling mask should be COUPLE_NONE for all cars. You can set it for the whole train with one call so it's easy.
2) Put another trigger a bit further ahead of the drop point, and when the train enters that trigger, check the size of its vehicle list. If it's the wrong size you can automatically stop the train immediately and tell the user to back up and try again. This is a little bit like what the built-in Navigate.Station() function does, so you can use its code as a template.