Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  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.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. b2soft Trainee 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. mze9412 Junior 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 Like x 1
  3. b2soft Trainee 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. JoeTheDestroyer Junior 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 Like x 1
  5. Malware Master Engineer

    Messages:
    9,549
    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. b2soft Trainee 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.
     
  7. Sinbad Senior Engineer

    Messages:
    2,788
    I haven't had any simspeed issues running a 60hz trigger now timer. my scripts use them exclusively as most of what I do is involved in motion control. I spend up to 6 hours a day in game on weekends with a couple running in the world at all times. the only time I see sim speed drops is when what I'm trying to move causes those funkey phantom forces that mis-aligned rotors and pistons are famous for. but once those are tracked down and aligned correctly, it all runs smooth.
     
  8. abrtn00101 Trainee Engineer

    Messages:
    59
    You're probably getting improved simspeed from using DX11.. Just a hunch. I was reluctant to switch over until a few weeks ago. I noticed that simspeed was stable even as some of my more demanding scripts that used to tank my framerate with DX9 ran side by side.
     
Thread Status:
This last post in this thread was made more than 31 days old.