John Cletheroe's
Trainz Hintz - TRS2004 Scenario Creation Tutorial


TRS2004 Scenario Creation Tutorial - How To Use The API To Access GameScript/TrainzScript Documentation

Introduction

The API is the single most useful source of GameScript/TrainzScript documentation. It is located here:

C:\Program Files\Auran\TRS2004\Scripts\doc\index.chm

It is a Microsoft compiled help document and can be opened by being double-clicked.

Within the index.chm document, the most useful section for scenario writers is the Class API Reference. Some of the other sections refer to writing GameScript/TrainzScript for rolling stock vehicles, industries, Driver session rules, driver commands, etc, none of which are directly relevant to scenario creation.

To start with, it is probably wise to get an overall feel for the purpose of each group of functions, including:

Example - How To Find The Correct Way To Wait For A Train To Leave A Junction

For some reason, you want a scenario to wait until the user drives their train away from a junction, then continue obeying more statements. Suppose you know such a thing is probably possible, but you don't know or can't remember how it is done.

Open the Class API Reference.

Your situation involves a train, a junction, and a "leave" event.

Clicking on the Train section in the lefthand column displays a page with a list of the Train functions at the top, followed by the details of each of them. To the newcomer, it is daunting, even more so as the newcomer things that this is just one of many sets of functions. It is obviously impossible to remember all this information. The trick is to remember how to find it.

Scanning down the list of Train functions, "Train.IsStillInJunction" appears to be of potential interest. However, its description mentions permits, a topic which the newcomer is probably not familiar with in the sense of programming them in GameScript/TrainzScript. So, perhaps it would be wise to look elsewhere.

The Junction set of functions doesn't contain anything obviously useful in this particular situation.

There is no "Leave" set of functions.

However, there is a different way to search. At the top of the lefthand column, switch from the "Contents" tab to the "Index" tab.

Now there's a huge number of entries under "Train" but nothing of obvious relevance.

However, under "Junction" the following items appear: JUNCTION_INNERLEAVE and JUNCTION_LEAVE. When you try to look at either of them, it says to select one of its subentries. Both only has one subentry, namely "Navigate". Clicking "Navigate" will lead to information on various functions including Navigate.OnJunction, which when checked can be seen to do exactly what is desired. (Finding the required function isn't always that easy.)

The function's documentation starts by specifying its syntax, its rules of grammar. In particular, it lists each of the function's parameters, what type of thing they must be and what their meaning is. There's also a link to the list of train junction event constants that you can use, one of which is JUNCTION_LEAVE. There's is also a statement of what value the function returns when it succeeds and when it fails. The only mystery now is the first parameter, the "running thread", a term with which the beginner is not familiar. This is an example of a situation where the API is far less helpful and obvious, probably because the expert programmers who wrote the API sprang forth from the womb born with complete knowledge of the concept of a running thread, and they cannot conceive that any moron could possibly require it to be explained. More seriously, the information is probably in the API somewhere but not easy to find. In fact the first parameter must be "me", without quotes, a fact only easily obtained by someone telling you, or you discovering it in someone else's scenario.

Thus the API is both incredibly useful and at times incredibly frustrating. However, in the absence of a "GameScript/TrainzScript For Dummies" book, using the API is the best option on offer.

As you become more familiar with GameScript/TrainzScript and the API, it will become easier to locate information. You will gain a feel for which groups of functions are most likely to be worth checking through, and the various techniques that can be used to search. Developing these skills will probably take quite a while unless you are already a programmer.


Index
Overall Site Home Page
About this personal web site JohnCletheroe

EMail me

Most recently modified 1-Aug-09