Page 1 of 1

lua help wanted (again)

Unread postPosted: Mon Jun 23, 2014 11:47 am
by KCJones
I want to slow down consist messages. To be more precise I need to delay them being transmitted from one end or delay them being implemented at the other.

Why? You may well ask. I am playing around with my USRA Heavy Mountains, developing one as a pusher engine. I know I did it with the Heavy Mikado. That was my starting point.

Now before radio, or at least radio in steam engines, for the engineers to communicate with each other they used whistle signals.

I want to replicate that so that the pusher engine repeats the whistle of the driven one. For that to sound "realistic" there needs to be a bit of a delay. At the moment I can get the pusher's whistle to sound but it is almost instantanious!!! I am sure no engineer has reactions that fast!!!!!!

There are two signals to send, on and off and both need to be delayed by the same amount.

Any help will be greatfully recieved and incorporated into my next offering.

Dick.

Re: lua help wanted (again)

Unread postPosted: Mon Jun 23, 2014 1:01 pm
by mrennie
Hi Dick,

it's very easy to do ... I'm doing something similar.

The key to it is this:

Code: Select all
CurrentTime = Call ("*:GetSimulationTime") -- time, in seconds, since the start of the scenario(


When a consist message is received, set some global variables to record what was received, and the time when you want to act on it (say, ActOnTime = CurrentTime + 1). Then, in the Update function, refresh your CurrentTime and see if CurrentTime > ActOnTime, and if it is, you do whatever the consist message said to do. The only complication with this is if you get several consist messages in quick succession, in which case you need to implement a FIFO buffer (or array) to store them in order.

Re: lua help wanted (again)

Unread postPosted: Mon Jun 23, 2014 3:20 pm
by KCJones
Great! Thanks I will play with that and see what I get. **!!bow!!** **!!bow!!**

Re: lua help wanted (again)

Unread postPosted: Mon Jun 23, 2014 5:08 pm
by Ericmopar
That's a bit of a quandary Dick. By the 30s and later, most railroads had primitive radios, since you can't hear the whistle on the pushers of a mile long freight train, over the noise of the lead engine anyhow...
IE neither engine crew on a long train could hear the other crew's whistle signals.
Signals in a yard were a different situation and are still used today. (on a limited basis)

The whistle signals were used mostly when trains were much shorter and engines were tiny compared to today's locos.
Also before they had air brakes. When they got air brakes established as a standard, the trains and locos rapidly grew in size.

Re: lua help wanted (again)

Unread postPosted: Mon Jun 23, 2014 5:47 pm
by KCJones
OK I can get it to delay the start of the pusher whistle, but then it won't stop!!!! Time to give it a rest I think and start with a fresh mind in the morning!!!

Re: lua help wanted (again)

Unread postPosted: Mon Jun 23, 2014 5:59 pm
by mrennie
KCJones wrote:OK I can get it to delay the start of the pusher whistle, but then it won't stop!!!! Time to give it a rest I think and start with a fresh mind in the morning!!!


Is the lead loco sending another consist message to tell the pusher to stop blowing the whistle? If so, you'd need to delay that command at the pusher too. If not, you could implement a timeout on blowing the pusher's whistle, in the same way as you do the initial delay, so that regardless of how long the lead loco blows its whistle, the pusher would always blow it for a fixed length of time.

Re: lua help wanted (again)

Unread postPosted: Mon Jun 23, 2014 6:11 pm
by KCJones
Yes I'm using the "Horn" command, one message for on and one for off. At the pusher end I am treating the messages independantly. I will look at it again in the morning when I am fresh. Thanks for your help anyway. !!*ok*!!

That's a bit of a quandary Dick.

I can't remember where I got that bit of information from. It is an interesting exercise anyway. Usefull when I get onto my rotary snow plough (plow) :D
Dick

Re: lua help wanted (again)

Unread postPosted: Mon Jun 23, 2014 6:31 pm
by buzz456
Ericmopar wrote:That's a bit of a quandary Dick. By the 30s and later, most railroads had primitive radios, since you can't hear the whistle on the pushers of a mile long freight train, over the noise of the lead engine anyhow...
IE neither engine crew on a long train could hear the other crew's whistle signals.
Signals in a yard were a different situation and are still used today. (on a limited basis)

The whistle signals were used mostly when trains were much shorter and engines were tiny compared to today's locos.
Also before they had air brakes. When they got air brakes established as a standard, the trains and locos rapidly grew in size.


That is not entirely true. I remember reading a story in Trains Magazine back in the fifties sometime about a stalled train somewhere in coal country and one of the great things about the story was them whistle signalling each other and things getting messed up leading to one engine backing up when the other one was going forward. That lead to a broken coupler that got replaced by replacing it with the one from the front of the front end engine. This was complete with pictures. I wish I could remember more details but it was a long time ago. All I remember was that these were big engines (articulated) on both ends. Like either C&O or N&W I think.

Re: lua help wanted (again)

Unread postPosted: Mon Jun 23, 2014 8:10 pm
by ozinoz
usefull when I get onto my rotary snow plough (plow) :D
Dick


!*drool*! **!!bow!!**

You are a tease....

!*cheers*!

Re: lua help wanted (again)

Unread postPosted: Mon Jun 23, 2014 10:32 pm
by arizonachris
ozinoz wrote:
usefull when I get onto my rotary snow plough (plow) :D
Dick


!*drool*! **!!bow!!**

You are a tease....

!*cheers*!


Yeah, huh. !*YAAA*!

Re: lua help wanted (again)

Unread postPosted: Tue Jul 01, 2014 9:24 pm
by Kali
Couple of key ideas/points

* Instead of immediately doing something with the message when you receive it ( in OnConsistMessage ), store it and set a timer.
* The parameter to Update() - RSC usually call it "time" or similar, doesn't matter what it's called - is the amount of time passed since the last loop. If you keep a running total of that number you'll have the time the script has been running in seconds, without needing to use a Call().

So ignoring details something along the lines of this messy but hopefully explanatory snippet:
Code: Select all
TOOT_ID = 10

function OnConsistMessage( msgID, vars I forget the name of )
   if msgID == TOOT_ID then
      toot_timer = math.random( 2,5)
    end
end

function Update( frameTime )
  if toot_timer ~= nil then
    if toot_timer > 0 then
      toot_timer = toot_timer - frameTime
    else
     Toot()
      toot_timer = nil
    end
  end
end

Re: lua help wanted (again)

Unread postPosted: Wed Jul 02, 2014 12:35 am
by KCJones
Thanks Kali. Something else I can play around with. *!!thnx!!*