Help with engine script

Help with engine script

Postby eyore » Fri Nov 20, 2015 11:51 am

Yet again I am struggling with lua!

I am trying to add two safety valve emitters to a loco, but can't seem to get them to switch on.

They have been added as children(Safe1 & Safe2) to the engine.bin file and are initialised as follows :-

Code: Select all
Call( "Safe1:SetEmitterActive", 0 );
   Call( "Safe2:SetEmitterActive", 0 );


They are called during the update function as follows:-

Code: Select all
-- Safety valves
   local Pressure = Call( "*:GetControlValue", "BoilerPressureGaugePSI", 0 );

   if Pressure >= 156.0 then
      Call( "Safe1:SetEmitterActive", 1 );
   else
      Call( "Safe1:SetEmitterActive", 0 );                  
   end
         
   if Pressure >= 160.0 then
      Call( "Safe2:SetEmitterActive", 1 );
   else
      Call( "Safe2:SetEmitterActive", 0 );         
   end


I thought I was missing and "end", but lua didn't like that, so my logic must be flawed somewhere.

Any ideas?
Phil

Image
User avatar
eyore
Passed Fireman
 
Posts: 139
Images: 12
Joined: Tue Apr 01, 2014 6:34 pm
Location: Lake District
Has thanked: 25 times
Been thanked: 67 times

Re: Help with engine script

Postby VictoryWorks » Fri Nov 20, 2015 12:38 pm

Hi Phil

Assuming the names are all correct (Safe1, Safe2, BoilerPressureGaugePSI) I can't see anything wrong with the code you've posted.
I'm not sure what other code you have so I'll make some general suggestions to check:

Is the Update function running - In Initialise Call ("BeginUpdate")
Have you stopped update running anywhere using Call ("EndUpdate")
If the above 2 things are ok then the most likely problem is that the code is failing before it reaches your safety code. Assuming you have script debugging running is it throwing out any failure messages?
User avatar
VictoryWorks
Driver
 
Posts: 333
Joined: Mon Apr 07, 2014 1:22 pm
Has thanked: 41 times
Been thanked: 224 times

Re: Help with engine script

Postby AndiS » Fri Nov 20, 2015 12:44 pm

The code does not look bad to me. Two ideas:

1) There is some issue with the set-up. To falsify this, I would just put
Call( "Safe1:SetEmitterActive", 1 );
in Update instead of the whole if-statement. E.g., you could put -- in front of lines 1, 3, 4 and 5 in each of these five-line blocks. Now the valves must go off. If they don't, the script is innocent and something else went wrong: naming, zero or invisible particles? Stuff like that.

2) Maybe the code is not reached at all. You would follow an old tradition of myself if you forget calling BeginUpdate or if the Update function terminates for whatever reason. Be sure to look at LogMate output from time to time. If there is some stupid typo leading to doing anything with nil, the script could break off a few lines before the code you showed.

P.S.: How comes Pete's brain is perfectly in sync with mine. :lol:
AndiS
Top Link Driver!
 
Posts: 736
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 268 times
Been thanked: 308 times

Re: Help with engine script

Postby eyore » Fri Nov 20, 2015 3:36 pm

Thanks guys.

For once my script was not the issue, it was the emitters themselves that weren't working. Doh!
Phil

Image
User avatar
eyore
Passed Fireman
 
Posts: 139
Images: 12
Joined: Tue Apr 01, 2014 6:34 pm
Location: Lake District
Has thanked: 25 times
Been thanked: 67 times

Re: Help with engine script

Postby VictoryWorks » Fri Nov 20, 2015 6:58 pm

Doh! Never mind, glad you figured it out.

Andi, I think we may have been TS'ing for so long we've developed a hive mind! :lol:
User avatar
VictoryWorks
Driver
 
Posts: 333
Joined: Mon Apr 07, 2014 1:22 pm
Has thanked: 41 times
Been thanked: 224 times


Return to Rolling Stock General

Who is online

Users browsing this forum: No registered users and 8 guests

cron