|
John Cletheroe's
Trainz Hintz - A Step-By-Step Guide To Making A Very Simple TRS2004 Scenario |
C:\Program Files\Auran\TRS2004\World\Custom\scenarios\name\name.gs(where "name" is the name of the scenario)
Near the bottom of the gs file, insert the following two statements between "playertrain.SetAutopilotMode( Train.CONTROL_MANUAL );" and "while( 1 == 1 )" (in other words, after giving the user control over the train, but before waiting until the user quits the scenario):
Navigate.OnTrigger(me, playertrain, "Trigger 1", Navigate.TRIGGER_ENTER);
Interface.SetObjective("Your train has entered the trigger", "");
The first of the above statements causes the execution of the scenario's statements to wait until the user runs the train over the trigger. During this period the scenario's clock continues to run, the user can drive the train, industries continue to consume and produce products, and if they were present then AI trains controlled by the scenario could continue to move. It may take some time to achieve an appreciation of the asynchronous and simultaneous nature of all the various actions in Trainz.
Navigate.OnTrigger specifies the OnTrigger function, in the Navigate set of functions. If "Navigate." is omitted, TRS2004 won't find the function.
The first parameter of the Navigate.OnTrigger function, "me", is a special variable. It's required here but I don't understand why.
The second parameter of the Navigate.OnTrigger function specifies which train to detect. It must not be in quotes.
The third parameter of the Navigate.OnTrigger function specifies which trigger is to be sensed. It must be enclosed in double-quotes. It must match precisely with the name given to the trigger when it was created in Surveyor.
The fourth and final parameter of the Navigate.OnTrigger function specifies what action to wait for. There are three options, namely to wait until the train enters the trigger (as in this example), to wait until the train exits the trigger, or to wait until the train stops in the trigger. TRIGGER_ENTER is a system variable with a numerical value, associated with the "Navigate" set of functions.
The second statement will not be obeyed until the user drives the train over the trigger.
The Interface.SetObjective function is a member of the Interface set of functions. It is confusingly named. It doesn't actually set an objective. Instead, it displays a message in the panel which is located fairly near the top left of the screen in a scenario. The name of the function comes from this panel sometimes being called the Scenario Objective Panel.
The first parameter of the Interface.SetObjective function specifies the message. It can be any string expression. If it is a literal string, as in this example, then it must be enclosed in double-quotes.
The second parameter of the Interface.SetObjective function can specify the filename of an icon to be displayed. If no icon is desired, this parameter can be two double-quotes (the empty string) or the word void (without quotes).
The details of these and numerous other functions are documented in the API.
When the scenario is run, and the train is driven over the trigger and the message is displayed, the screen should look similar to this:
After the train has entered the trigger and the message has been displayed, the scenario will enter the endless "while" loop, allowing the user to continue driving the train until they exit the scenario. Leaving and re-entering the trigger will not cause the message to reappear, as that section of coding has already been obeyed and will not be obeyed again. There are ways of making such messages appear repeatedly but these are a little too complicated for this tutorial.
Like the trackmark, the trigger is invisible when the scenario is run. With your own test layouts you might want to place an object such as a tree or a scenery building in line with the trigger so that you can see its position. However, bear in mind that modifying a layout after creating scenarios for it is likely to wreck the scenarios.
Part Fourteen: Adding A Trigger
Part Sixteen: Some More GameScript/TrainzScript Functions And Facilities To Explore
Most recently modified 16-Apr-10