BVE WorldWide
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Delay code for RotateFunction?

2 posters

Go down

Delay code for RotateFunction? Empty Delay code for RotateFunction?

Post by 1969 St. Louis R-40M Wed Jul 21, 2021 9:50 am

I'm working on trippers for time control signals, but since I'm not so good at .ANIMATED, I can't figure out a functional code that would lay the trip arm down after a certain time which is triggered by trackdistance. (trackdistance because I can't be asked to make a plugin where section lengths can be detected)

First, here's the delay code (extracted from the developer documentation) of the time control signal at 20MPH:
States = Red.csv, Yellow.csv
StateFunction = if[trackDistance>100 | section==0 | section==2, 0, min[value + 0.5*delta/8.94775, 1]]

I need the trip arm to work the same way, however since it's a RotateFunction (the trip arm rotates down by -0.7 from 0), the "min" function makes the trip arm to rotate infinitely. I tried other alternatives but no success at all.

Is there an alternative I can use other than the "min" function for a delay? I need the trip arm to rotate down by -0.7 from 0, 8.94775 seconds after the train is 100 meters away from the tripper. Preferably as a condition that I can include here: if[trackDistance>100 | section==0 | section==2, 0, ..........]

I will delete the post if I figure it out, but if it's still here, feel free to help.

Thanks
1969 St. Louis R-40M
1969 St. Louis R-40M

Posts : 33
Join date : 2020-02-07

Rakago likes this post

Back to top Go down

Delay code for RotateFunction? Empty Re: Delay code for RotateFunction?

Post by leezer3 Wed Jul 21, 2021 10:31 am

Let's look at this logically Smile
Your important code is this:
min[value + 0.5*delta/8.94775, 1]


It does the following:
Returns the *minimum* of the last function result (value) PLUS
05 * the elapsed time (delta) divided by 8.94775

OR 1

So, it'll therefore count up to one, and then stop.
The state function rounds this, so it'll only display states 0 and one

You're trying to get this to work in a rotation function, which is a little more involved, and will require a statefunction too. (As the rotation function doesn't round)
Fortunately, your statefunction is *identical* to the one you've got above Razz

Our rotate function is simplicity itself- It just needs a quick state check:
Code:
RotateYFunction = if[currentState == 0, 0, -0.7]
If our current state is zero, it performs no rotation. Otherwise, it performs your desired rotation.

Putting this together:
Code:
States = SignalArm.csv, SignalArm.csv
StateFunction = if[trackDistance>100 | section==0 | section==2, 0, min[value + 0.5*delta/8.94775, 1]]
RotateYFunction = if[currentState == 0, 0, -0.7]

http://web.archive.org/web/20100902041536/http://openbve.freeforums.org/delay-in-approach-controlled-signals-t1195.html#p5378

leezer3

Posts : 1955
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Gothpaladinus and 1969 St. Louis R-40M like this post

Back to top Go down

Delay code for RotateFunction? Empty Re: Delay code for RotateFunction?

Post by 1969 St. Louis R-40M Wed Jul 21, 2021 10:56 am

I can't thank you enough! I've been trying different things for more than a hour, while ripping my hair off!
Turns out the solution was very simple.
With the addition of RotateXDamping, it works just like I wanted.
Thanks again!
1969 St. Louis R-40M
1969 St. Louis R-40M

Posts : 33
Join date : 2020-02-07

Gothpaladinus likes this post

Back to top Go down

Delay code for RotateFunction? Empty Re: Delay code for RotateFunction?

Post by leezer3 Wed Jul 21, 2021 11:02 am

No problem Smile
I've added this example to the documentation, and fixed the link so that it shows the archive page.

leezer3

Posts : 1955
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Gothpaladinus and Midnight Express Ginga81 like this post

Back to top Go down

Delay code for RotateFunction? Empty Re: Delay code for RotateFunction?

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum