Jump to content

Variable Timers?


Recommended Posts

I'm trying to come up with a way to make something happen that is probably not possible. Or at least might require some fancy Lua code or jigging about with User-Defined functions....

So, I have this very simple layout that is a single station on the middle of a section of elevated track the sort of thing you might see in New York, or Tokyo, even London has some. I imagine a place like Munich might...? Anyway there are 10 brightly coloured Urban Mass Transit Vehicles zipping back and fourth between two fiddle yards that each have 4 tracks, and the fiddle yards generate a random number 1-4 to decide which track to release, giving a realistically unpredictable sequence of trains.

The release prompt is on a timer.

I have set the layout to run on sim-time, with a day = 1:36:00. That's 96 minutes, so 1 hour is 4 minutes.

What I would like to do is change the duration of the timer so that between 7:00 am and 9:00am and again between 5:00pm and 7:00pm it releases a train every 15 (real) seconds, and during the day it releases one every 30 seconds, and perhaps between 11:00pm and 4:00am releases one every minute of real time.

The best I can come up with is deactivating the event that uses the fast timer and activating a different event that uses a slower timer, both of which call the same user-defined event to actually release the trains...

Thoughts?

2055305947_UrbanElScreenprint.thumb.jpg.9aa533d74936df2383bb9a6049714257.jpg

Link to comment
Share on other sites

Sweet are the uses of insomnia....

Couldn't sleep so I had a go at implementing the above solution.

Three timers, one called "Peak" running at 16 seconds (4 minutes sim time), one called "Off Peak" running at 32 seconds (8 minutes) and one called Late Night running at 1 minute (15 minutes).

Each timer has it's own "When timer expires" event,  all three do exactly the same thing: Call both the events (that were originally timer driven, but are now User-Defined) that release a train randomly from one or other fiddle yard. Originally each yard had it's own timer and it's own event. I suppose I could merge them but I can't be bothered! Having the events self contained meant it was easy to just change them from timer-driven to user-defined with no parameters.

Now comes the clever bit that makes it all work.

Six "Time activated" events. "Start Morning Rush" activates at 07:00 and enables "Peak", Disables "Off Peak". "End Morning Rush" reverses that. at 09:00. At 17:00 "Start Evening Rush" and at 19:00 "End Evening Rush" do the same. And then at 23:00 "Start Late Night" disables "Off Peak and enables "Late Night" while at 05:00 "End Late Night" puts it back the other way.

And it works! I haven't run it all the way through a 24hr loop yet, but I ran it from about 10pm to about 10am, enough to see what happens.

It's probably not the most elegant solution, but one thing I learned from 18 years in IT is that there is no one right answer, and if it works, don't fix it!

Now I must see about getting some sleep, having got that out of my head!

Link to comment
Share on other sites

Hello Simon,

this would be my suggestion (and it doesn't differ much from your approach):

  • use a specified time of day as a trigger (as you do already)
  • when triggered, set a module variable to the new frequency value
  • use that variable to determine the duration for your release timer
    (please note that the timer doesn't auto-start. Instead, the event "timer expires" contains an action to start the timer.)

example layout: changing traffic frequency.mbp

Edited by Goetz
added remarks
Link to comment
Share on other sites

Hmm... Rats! I forgot that.

I had the timers at each end set to auto restart, and with that option set there's no way to specify frequency. I completely forgot that if auto restart is taken off, the "Start Timer" action allows a time to be specified. *Facepalm*

Thanks. Next time... I'll leave it as it is for now - as I said, "If it works, don't fix it"!

 

Edited by simonjackson1964
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...