Snow plough script help

Snow plough script help

Postby eyore » Sun Sep 06, 2015 9:56 am

Despite my lack of knowledge of lua, and thanks to reading the work of others, I have managed to get a snow plough in game and working, with suitable emitters for the snow plumes. However, I have one small problem, the emitters work whenever the plough moves, but I only want them to work if there's snow on the ground.

Just Trains ZZA get round this by having two ploughs, one with emitters and one without, but this seems a less than elegant way of doing it, so my question is, is it possible to add some code to the wagon script that detects the season, so only allowing the emitters to work in winter?
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: Snow plough script help

Postby AndiS » Sun Sep 06, 2015 2:29 pm

According to nschichan and chrisell
SysCall("ScenarioManager:GetSeason")
returns 0,1,2 or 3, corresponding to spring, summer, autumn and winter.

According to Kariban
Call("YourEmitter:SetEmitterActive", 1 )
turns on the emitter (and 0 turns it off). YourEmitter is the name for the article emitting child you assigned in the blueprint.
AndiS
Top Link Driver!
 
Posts: 736
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 268 times
Been thanked: 308 times

Re: Snow plough script help

Postby eyore » Sun Sep 06, 2015 8:06 pm

Thanks Andi.

All I have to do now is put my non-existent lua skills to use and add that to the wagon script.
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: Snow plough script help

Postby AndiS » Sun Sep 06, 2015 8:49 pm

You can always dump the script here and see how many bugs my wannabe omniscience can add before such a simple thing actually works.
AndiS
Top Link Driver!
 
Posts: 736
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 268 times
Been thanked: 308 times

Re: Snow plough script help

Postby eyore » Sun Sep 06, 2015 9:42 pm

Thanks for the offer Andi.

I think this is the relevant part of the script, as the rest is the calls to switch the emitters on and off and that works.

Code: Select all
-- Plough Script


speed = 0
SNOWLO = false
SNOWMID = false
SNOWHI = false
SnowLoStart = 3.58
SnowMidStart = 6.71
SnowHiStart = 8.94




function Initialise ()

  StopSnow ()
  Call("BeginUpdate");

end

function Update( time )

 
  speed = Call( "GetSpeed" )
   
  if speed > SnowLoStart and speed < SnowMidStart and SNOWLO == false then
    StartSnowLo ( )
  elseif speed < SnowLoStart and SNOWLO == true then
    StopSnow ( )
  elseif speed > SnowMidStart and SNOWLO == true then
    StopSnow ( )
  elseif speed > SnowMidStart and speed < SnowHiStart and SNOWMID == false then
    StartSnowMid ( )
  elseif speed < SnowMidStart and SNOWMID == true then
    StopSnow ( )
  elseif speed > SnowHiStart and SNOWMID == true then
    StopSnow ( )
  elseif speed > SnowHiStart and SNOWHI == false then
    StartSnowHi ( )
  elseif speed < SnowHiStart and SNOWHI == true then
    StopSnow ( )

  else 
  end;
 

end


I'm sure the answer is fairly obvious but my old brain struggles with lua.
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: Snow plough script help

Postby AndiS » Mon Sep 07, 2015 7:55 am

There is one super elegant solution in your case: You only do BeginUpdate if it is winter. That means that if the season is not winter, you do not tell the system to call Update. That means that no time is wasted on calling Update when you don't plan to do anything there anyway.

Be warned that this is only a good idea if Update is exactly what you show. If you do something else, like flashing some light or running some animation in seasons other than winter, then it is a bad idea.

Code: Select all
function Initialise ()

  StopSnow ()

  if SysCall("ScenarioManager:GetSeason") == 3 then
    Call("BeginUpdate");
  end

end


Don't worry about your brain. This example clearly shows how Lua scripts for RW are a bad way of learning programming. There are simple things like "if season is winter" mixed with very complex ones like telling the system whether to call some other function at some later time.
AndiS
Top Link Driver!
 
Posts: 736
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 268 times
Been thanked: 308 times

Re: Snow plough script help

Postby eyore » Mon Sep 07, 2015 8:25 am

Thank you Andi, that worked a treat.


Image
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: Snow plough script help

Postby AndiS » Mon Sep 07, 2015 9:47 am

Phew, I got good luck in the morning!
Should do more while I am not awake. :lol:
AndiS
Top Link Driver!
 
Posts: 736
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 268 times
Been thanked: 308 times


Return to Rolling Stock General

Who is online

Users browsing this forum: No registered users and 1 guest