Wednesday, October 31, 2012

3DC to Railworks - Locomotive: Basic Scripting

3DC to Railworks - Locomotive: Basic Scripting
by Jerry "SMMDigital" Conaway


< PreviousIndexNext >


In previous sections of this tutorial, we have created the physical lenses, a switch, the point lights, and control values for an interior cab light. Despite all of this, the cab light still won't work. We need to add a few lines of basic code to our Engine Script in order to get it to work.

Start out by opening your LUA script, located in the Default/Simulation folder. You can open this file using any good word editing program (Notepad++ is my weapon of choice). Keep in mind that we are using script from the default ES44.

As you can see, I have added a line of code that wasn't here originally:

Call( "CabLight:Activate", 0) 

What this does is tell the game that when this locomotive is chosen in the game, it should look into the Locomotive Blueprint and initialize the "CabLight" child that we placed there.

The second section of the LUA file is called "function OnControlValueChange ( name, index, value )". This section tells that game that if a locomotive control is chosen in the game, then if that control value is listed in this script the script will govern how it acts in the game. If these values are not present in your LUA script, then you need to place them there.

The last section where all the work is done is called "function Update ( time )". We need to place a couple of lines of code here in order to finalize the light's operation.

The first line:

if Call("*:GetControlValue", "DriverCabLight", 0) == 1 then

tells the script that when the driver cab light switch, which is named as a control sub-element of "DriverCabLight" (point 443) in the locomotive blueprint, is activated...


... look to the second line:

Call( "CabLight:Activate", 1)

which calls on the game to activate the "CabLight" Child object in the Locomotive Blueprint...

... otherwise the third line

Call( "CabLight:Activate", 0)

says if the switch isn't thrown or is thrown into the "off" position, leave the "CabLight" child object alone and keep it off.

Your cab light should be ready to use now when you flip the cab light switch.


< PreviousIndexNext >


Published with permission from Jerry Conaway, 2012

No comments:

Post a Comment