1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

# Update rate

Discussion in 'Programming Questions and Suggestions' started by b2soft, Aug 11, 2015.

This last post in this thread was made more than 31 days old.
1. ### b2softTrainee Engineer

Messages:
38
Hello

I have PB with script, that checks piston length and if it is near needed level - decreases speed of it (I wanna make elevator)
There are 3 problems:
1. Update loop is implemented by using Timer that triggers PB and himself. Update 1 time/sec is awful, because in 1 second elevator goes for 1.5 metres. It's very poor precision... How to overclock PB updates? Can I trigger Main() with UPS (60 times/s)?

2. A little bug with piston. After ResetVelocity Action or when I set 0.0 m/s it has 2 values: -0.0 m/s and 0.0 m/s. Maybe, Keen doesn't know about round values.... So problem is: when I apply 3 times Increase Velocity to 0.0 m/s in result I have 1.5 m/s. When apply 3 times Increase Velocity to -0.0m/s in result I have 1.0 m/s. Same with Decrease. When Decrease from 0.0 m/s 4 times I have -1.5 m/s and when decrease from -0.0 m/s 4 times -2.0 m/s.

3. Interesting bug. If I have Vector3 vec = SomeBlock.GetPosition(); and then try to Echo(vec.X.ToString() + " " + vec.Y.ToString() + " " + vec.Z.ToString()); I see three same values equals vec.Y. WTF?
And vec.Y * vec.Y is crashing dedicated server...

Any suggestions?

Last edited: Aug 11, 2015
2. ### mze9412Junior Engineer

Messages:
791
1) No clue, sorry

2)
Why not set the speed directly via SetValue? Then you do not depend on the increase/decrease actions at all

3)
Use vec.Dim(0) to get X, vec.Dim(1) to get Y and vec.Dim(2) to get Z. The properties are bugged (there is a pending source code pull request to fix properties)

• Like x 1
3. ### b2softTrainee Engineer

Messages:
38
1. Not good
2. SetValue? Hmm. Will try. Maybe 1st issue will go away with normal speed)
3. Thanks, I parsed via string...

List of values I can get in documentation?

4. ### JoeTheDestroyerJunior Engineer

Messages:
573
Use TriggerNow on the timer, rather than Start. This triggers the timer on the next update, giving you an effective 60 UPS rate. Be warned though, TriggerNow has problems surviving a save/load cycle. If this is a issue for you, you may need a second timer as a backup, running at a slower rate and triggering the first.

• Like x 1
5. ### MalwareMaster Engineer

Messages:
9,663
Also be warned that I have seen framerate (simspeed) hickups with this technique.

I have a set GitHub of pull requests awaiting review which will allow the programmable block to enqueue itself (or another programmable block) to be run in the next tick which I hope and think will alleviate this, plus make it easier to make far more efficient scripts that only run and repeat when they are needed - without the need of the timer block.

6. ### b2softTrainee Engineer

Messages:
38
Or it's will be useful, if make in PB property "Clock Speed"
To set in calls per second. For really huge needings - 60 calls per second (equals to UPS), for small scripts - 2-3 calls per second.