Jump to content

question about setTimer ms precision


Aibo

Recommended Posts

currently im making something liek a «tracker» (aha, i know it IS stupid :D), and using timer to play sounds and stuff.

so milliseconds for the timer are calcutated from BPM (beats per minute) like this:

ms = math.floor(60000/bpm/4)

thing is, for example:

INFO: BPM: 89 - timer ms: 168

INFO: BPM: 111 - timer ms: 135

looks like 135 and 168 ms have absolutely no difference for the timer (89 and 111 BPM plays the same),

so i am wondering what is the exact timer ms "precision", or "steps" maybe, cause right now i cant directly convert any BPM value to timer ms.

PS: resource is here: https://community.multitheftauto.com/index.php?p= ... ls&id=1355

Link to comment

You'd be much better off doing it using onClientRender, which is called every frame. Timers aren't really designed (or able) to be terribly accurate. Of course, bear in mind that with onClientRender frames can be a long time apart. Usually they're going to be 1/20s to 1/30s apart, but if the player pauses the game it could be minutes :)

168ms and 135ms are exactly 33ms apart, so for the 135ms timer is only going to be guaranteed to occur on a different frame to the 168ms timer if the game is running at over 30 FPS.

So the precision is basically the frame time. All the timers are triggered at the same point each frame.

Generally, in games, the audio runs on a separate thread with a high priority to avoid such timing issues (though they're generally having to do more than just trigger sounds).

I've added some more explanation on the wiki.

Link to comment

One alternative would be to write a module that had it's own thread for dealing with this and scheduling audio. I'm sure there's some way we could support this better, but it's a fairly niche use!

Good work though - with this and all your other resources.

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...