Issuu on Google+

A small Guide to Scripting a Cabin

! %

" #

&&

&

&

& )*

&

& #

# $ '

(

(

Basics %& ! &

&

'

0 # $ 3,

%& ! ! / & !

$! -

& +,$! & !

&&

.

&

! /'

!

%& ! / &

&

2

&! '#

&

! !

1 # $

#

, 3, &$#

%& !

.

1 &

# &

'# & !

! !&

3, &

! $

& &

&

4 5 !

. 1 6 )$! .

% # & include "DefaultSteamCabin.gs"

$

!

( &

/

& 7

class MySteamCabin isclass DefaultSteamCabin { public void Init(void) { hasAnimatedFireman = false; inherited(); } }; %& #7 script "mysteamcabin" class "MySteamCabin"

&

7

!

#

&

)

1


%& !

/ &

&

!

&

''01

#

8

!

# #

&

! &

Enhancing the default cabin features . &

! $!

& & !

) 1$ !

&&

& /

#

&

&& & %& ! & $ !

! # ! # (

&, #

! $

1! $

& !

#

! &

&

!

$

#

!

&

&

$

#

/ ( $

& &

&

#

# 4&

&

$#! 1 ;

9

&

6 %& ! $!

+,

&

-&

#

/: !

)

7

&

Connection between config.txt and script file <& & )

! %&

(

&

# $ $

# $

5 ! )

#

& $

'# '

%& !

&

<#=

&

$

#

) &

# $

$

!

#

&

& (

'# ' ) !

*

<#=

!

$!

8

& &

&

#

!

! CabinControl speedometer; CabinControl throttle_lever; CabinControl reverser_lever; 6

'# ' >

//Speed indicator. //Throttle lever. //Reverser lever.

#= "

(

#

/

# &

& &

&

)1

&

#

&

&

public void Init(void) { speedometer = GetNamedControl("speedo_needle"); throttle_lever = GetNamedControl("throttle_lever"); reverser_lever = GetNamedControl("reverser_lever"); }

& &

0 ? ) )

' $ 7

&

'# ' !

#=

( 2 (

)


Mesh-Table { Default { Mesh "interior.im" Auto-Create 1 } reverser_lever { Kind "lever" ... } speedo_needle { Kind "needle" ... } throttle_lever { Kind "lever" ... } }

The â&#x20AC;&#x153;Updateâ&#x20AC;? Function 8 &

( & #

& !

!$ )

.

& = &

! & 7

if (speedometer) speedometer.SetValue(train.GetVelocity()); "

!

&

,

(&

)

& &

if (reverser_lever) { reverser_lever.SetValue(loco.GetEngineSetting("reverser")); }

& ) !& reverser_lever { kind "lever" auto-create 1 mesh "reverser_lever.pm" att "a.reverser_lever" limits 0,2 angles 0.55,-0.55 notches 0,0.5,1

@

( (

7


notchheight 1,1,1 att-parent "default" } 6

A

(

)

&

!

" & # $ /? 7 ! # 1 ? =

8 ,

& "

" % !

$B

/

, &

1 &

&

!

( ! &

) , D

.C%

&

& /1

$

B

&

> #

&

$ , D

/1 &

& $

$

&

# , D / E F $G EH 1 * ) 7 reverser_lever.SetValue(1); &

&B 2 -

(

&

I

(

&

& $

& $ )

%

*

# $

(

throttle_lever { kind "lever" auto-create 1 mesh "throttle_lever.pm" att "a.thottle_lever" limits 0,16 angles 1.2,0 notches 0,0.0625,0.125,0.1875,0.25,0.3125,0.375,0.4375,0.5,0.5625, 0.625,0.6875,0.75,0.8125,0.875,0.9375,1 notchheight 2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2 radius 0.35 att-parent "default" } BJC BJ

/&

& $

/BKI

BK1 5 &B

K 1 .

BKI &

BK$ &

&B

throttle_lever.SetValue(4) @

#

9

! ! !

I

& BK

"

#

# $

%

&

#

'(

)


%& ! & ( 7 public void Update(void) { if (!loco or !train) return;

&

$!

-

&

(

if (speedometer) { speedometer.SetValue(train.GetVelocity()); } inherited(); } %

)

&

!

.

#

/

&

2

'# 1

The “UserSetControl” Function & &

&

&

• •

& (

&

&

&

&

&

% # $

7 L '

L

/

&

M

,

& # -

$

-

&

!

1

&

>;

=

&

!

void UserSetControl(CabinControl control, float value) { ... if (control == reverser_lever) { loco.SetEngineSetting("reverser", value); } else if (control == throttle_lever) { loco.SetEngineSetting("throttle", value); } ... ; &

&

& !

$

# &

#

. $

& . !

!$ %&

& *

$ ! &&

& & &

! &

$

#

1 # (

/ ) $#

-


%& ! &

& )

! &

$!

! *

M

:!

& void UserSetControl(CabinControl control, float value) { ... if (control == reverser_lever) { loco.SetEngineSetting("reverser", value); } else if (control == throttle_lever) { loco.SetEngineSetting("throttle", value); } ... else { inherited(control, value); } }

! ( &

& !


The UserPressKey Function (

)*

&

&

&

(!

M& (!

!.

& & &

(! :! ; , . % < , , & O, ? , & O? * + , & O*

&!

#

( !#

& ( !/ #!.

!( !#

N

N

1

!&

(! &

&

$

&

& (

$# #

7

N N N N @ # @# ( @ N = N N = N N @ # @ @ N# N N# N N N N N # N&

%& ! !

&

& (!

$

!

#

$

!

void UserPressKey(string s) { if (!loco) { return; } ... if (s == "steam-regulator-up") { ... } else if (s == "steam-regulator-down") { ... } else if (s == "train_cabin_brake_application") { ... } else inherited(s); } %

) , $

-

.

(& /

+ , 0/ %& & ( )* #

/ &4

2 -

( )

(

& (

&

, ! #

# $#

, # &

# &

% +

1

2


,

,

(!

& (!

8 !

!

&

! !

! $#

!

... if (s == "steam-regulator-up") { int notch = loco.GetEngineSetting("throttle"); if (notch < 16) { loco.SetEngineSetting("throttle", notch + 1); } } ... & !

$ " /&

& /

& ! & # 1

&

"& BK1 . ; ! &&

%

) ! !

-

!$

)

" $#

BJ BK " & M

34 & $

&


Cabin tutorian for trainz