lua help wanted (again)

Announcements and Discussion about Dick Cowen's BritKits Development

lua help wanted (again)

Unread postby KCJones » Mon Jun 23, 2014 11:47 am

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.
User avatar
KCJones
 
Posts: 872
Joined: Fri Feb 13, 2009 4:05 pm
Location: UK Somewhere between Hereford and Shrewsbury

Re: lua help wanted (again)

Unread postby mrennie » Mon Jun 23, 2014 1:01 pm

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.
User avatar
mrennie
 
Posts: 3214
Joined: Wed May 30, 2012 12:22 pm

Re: lua help wanted (again)

Unread postby KCJones » Mon Jun 23, 2014 3:20 pm

Great! Thanks I will play with that and see what I get. **!!bow!!** **!!bow!!**
User avatar
KCJones
 
Posts: 872
Joined: Fri Feb 13, 2009 4:05 pm
Location: UK Somewhere between Hereford and Shrewsbury

Re: lua help wanted (again)

Unread postby Ericmopar » Mon Jun 23, 2014 5:08 pm

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.
New build. i7-7700k, MSI Z270 Gaming M5 Mobo, Hyper 212 Evo, Corsair DDR4 3200 Mhz RAM, Klipsch Pro Mediea 2.1 Speakers, Samsung 850 Evo SSD, HAF XM Case, Asus Strix GTX 1070 and Cooler Master Storm XT Keyboard.
Slick with Pretty Rainbow Colors.
User avatar
Ericmopar
 
Posts: 2797
Joined: Mon May 13, 2013 12:35 am
Location: Henderson NV.

Re: lua help wanted (again)

Unread postby KCJones » Mon Jun 23, 2014 5:47 pm

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!!!
User avatar
KCJones
 
Posts: 872
Joined: Fri Feb 13, 2009 4:05 pm
Location: UK Somewhere between Hereford and Shrewsbury

Re: lua help wanted (again)

Unread postby mrennie » Mon Jun 23, 2014 5:59 pm

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.
User avatar
mrennie
 
Posts: 3214
Joined: Wed May 30, 2012 12:22 pm

Re: lua help wanted (again)

Unread postby KCJones » Mon Jun 23, 2014 6:11 pm

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
User avatar
KCJones
 
Posts: 872
Joined: Fri Feb 13, 2009 4:05 pm
Location: UK Somewhere between Hereford and Shrewsbury

Re: lua help wanted (again)

Unread postby buzz456 » Mon Jun 23, 2014 6:31 pm

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.
Buzz
39 and holding.
"Some people find fault like there's a reward for it."- Zig Ziglar
"If you can dream it you can do it."- Walt Disney
Image
User avatar
buzz456
Site Admin
 
Posts: 20939
Joined: Sun Mar 21, 2010 8:30 am
Location: SW Florida

Re: lua help wanted (again)

Unread postby ozinoz » Mon Jun 23, 2014 8:10 pm

usefull when I get onto my rotary snow plough (plow) :D
Dick


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

You are a tease....

!*cheers*!
ozinoz
 
Posts: 1622
Joined: Fri Feb 20, 2009 1:59 am
Location: Antipodes

Re: lua help wanted (again)

Unread postby arizonachris » Mon Jun 23, 2014 10:32 pm

ozinoz wrote:
usefull when I get onto my rotary snow plough (plow) :D
Dick


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

You are a tease....

!*cheers*!


Yeah, huh. !*YAAA*!
Ryzen 7 2700K, Asus Prime X570P, 32Gb DDR4, 2x 1Tb M.2 SSD's, RTX2060 6Gb, Occulus Rift
Win 10 Pro 64bit, keyboard/ mouse/ wheel/ pedals/ baseball bat
Security Coordinator on the Battleship Iowa
User avatar
arizonachris
 
Posts: 3955
Joined: Sun Mar 21, 2010 10:36 am
Location: Southern California

Re: lua help wanted (again)

Unread postby Kali » Tue Jul 01, 2014 9:24 pm

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
Kali
 
Posts: 1600
Joined: Mon Mar 14, 2011 1:00 am
Location: England-by-Sea

Re: lua help wanted (again)

Unread postby KCJones » Wed Jul 02, 2014 12:35 am

Thanks Kali. Something else I can play around with. *!!thnx!!*
User avatar
KCJones
 
Posts: 872
Joined: Fri Feb 13, 2009 4:05 pm
Location: UK Somewhere between Hereford and Shrewsbury


Return to BritKits

Who is online

Users browsing this forum: No registered users and 1 guest

cron