John Cletheroe's
Trainz Hintz - TRS2004 Scenario Creation Tutorial


TRS2004 Scenario Creation Tutorial - A Quick Guide To GameScript/TrainzScript For Visual BASIC Programmers

This list is intended to cover the fundamental differences between the two languages. There are many more detailed and obscure differences.

Visual BASIC GameScript
Programs are created with a graphical integrated development environment (IDE). Programs are created with a text editor program.
The language is primarily event driven. Separate sections of code react to user events such as clicking on a command button. The language is not primarily event driven but handler functions can be used to react to events if desired. In addition, schedules can asynchronously control AI trains including reacting to their events and (I think) threads can be used to perform asynchronous operations including reacting to events.
The language's syntax is based on that of traditional BASIC, with object-oriented and other additions. The language's syntax is based on that of "C", with object-oriented and other additions.
When a program is run it initially obeys the Form > Load or similar event section of code, if there is one. If there isn't one, it waits for a user event to occur and then runs its section of code. When a program is run it initially obeys the "main" function, of which there has to be one.
No semi-colons are required on the ends of statements (unless you put more than one statement per line, in which case a colon is used to separate them). Semi-colons are required on the end of most statements, but not:
  • do

  • include

  • for

  • if

  • switch

  • while

  • the opening line of a user-defined function's definition

  • open curly bracket {

  • Close curly bracket } (except for the last close curly bracket of a class, which must have a semi-colon after it)
Each statement within a FOR loop (etc) must have a semi-colon on its end.
No round brackets are required around FOR loop control information or IF/THEN relational expressions. Round brackets are required for both of these.
The end of block of statements inside a FOR loop is indicated by a NEXT statement. A block of statements in a FOR loop is surrounded by curly brackets.
The end of block of statements inside a WHILE loop is indicated by a WEND statement. A block of statements in a WHILE loop is surrounded by curly brackets.
The end of a block of statements which are controlled by an IF statement is indicated by an END IF statement. A block of statements controlled by an IF statement is surrounded by curly brackets.
Array subscripts enclosed by round brackets. Array subscripts enclosed by square brackets.
DIM A(10) declares an array whose subscripts run from 0 to 10. float A[10]; declares an array whose subscripts run from 0 to 9.
Variable declarations are prefixed by the keyword DIM and optionally followed by a specification of what type of variable they are, for example:
Dim a as Int
Variable declarations are prefixed by a keyword which indicates which type of variable they are, for example:
int a;
User-defined function definitions are prefixed by the keyword Function. User-defined function definitions are usually prefixed by the name of the type of variable they return. They can be distinguished from variable declarations by the presence of their parameter list in round brackets after their name, then on the following lines by their block of statements in curly brackets.
Comments are prefixed with a single-quote ' Comments are prefixed with two forward slashes //
No multiple operator combinations are permitted in assignment statements. Numerous multiple operator combinations are permitted in assignment statements, for example ++. Assignment statements can also be written conventionally if preferred.
The meaning and variable type of each parameter is fixed. The meaning and variable type of each parameter can vary, depending on the number of parameters and the parameter's variable type. For example, the camera angles in the SetCameraAngle function are taken as being in degrees if they are integers but as being in radians if they are floats.
Various functions are provided in the language to convert from one variable type to another, for example NUM and STR. The cast statement is used to convert from one variable type to another.
The string concatenation operator is ampersand & The string concatenation operator is a plus sign +
One equals sign is used for both assignment statements and in relational expressions. One equals sign is used for assignment statements, but two equals signs are used in relational expressions.
Not equals is <> Not equals is !=
If a=5 Then
   b=10
   c=8
   End If
if (a==5)
   {
   b=10;
   c=8;
   }
For n=1 To 10 Step 0.5
   b(n)=2*n+1
   c(n)=3*n-8
Next n
for (n=1; n<=10; n=n+0.5)
   {
   b[n]=2*n+1;
   c[n]=3*n-8;
   }
Carat ^ is used as the exponentiation operator, for example n^3 is n cubed. There is no exponentiation operator.
Trig functions (SIN, COS and TAN) are provided as part of the language. The language does not include trig functions.
A property of an object can be set and read directly, for example:
TextBox1.Left=300
a=TextBox1.Height
In most cases a "Set" function must be used to set an object's property, and a "Get" function must be used to read an object's property, for example:
AITrain01.SetDCCThrottle( -0.35 );
float LogWagonLength = LogWagons01.GetVehicles()[ 0 ].GetLength();


Index
Overall Site Home Page
About this personal web site JohnCletheroe

EMail me

Most recently modified 16-Apr-10