• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Counting milliseconds

S

Skible

Guest
Hi!
I'm working on a script that would delay sound by certain amount of milliseconds. If I understand correctly, one step with the room speed of 60 is 17ms and with the room speed of 30 it would be 33ms, right? If I would like to have accuracy of the delay somewhere around 3ms I would need the room speed to be something like 300. Which is ridiculous. Is there some better way to do this?

If there is no easy way to do this, I guess I have to go with less accuracy.
 

Phil Strahl

Member
i think you could make this work with audio_sound_set_track_position(), so that you have a value counting milliseconds of the game e.g. by just adding up delta_time each step. e.g.
Code:
var delay_ms = 15; 
audio_actual_time_ms += delta_time;
audio_play_time_sec = (audio_actual_time - delay) / 1000 
audio_sound_set_track_position(audio_play_time_sec);
Disclaimer: I haven't tested this but maybe it'll get you on the right track.
 

Yal

šŸ§ *penguin noises*
GMC Elder
If I remember correctly, the current_time variable is the time since system boot in milliseconds. You still won't get a higher precision than one game step, but you could simulate as many actions as would transpire in one game step (in the correct order) to catch up, depending on how often / rarely you expect them to happen (if they're gonna happen CONSTANTLY it might be easier to have 300 frames per second).

Also, you can turn off automatic drawing, which helps you run game logic independently of the drawn frames... could help making 300fps less ridiculous?
 
S

Skible

Guest
i think you could make this work with audio_sound_set_track_position(), so that you have a value counting milliseconds of the game e.g. by just adding up delta_time each step. e.g.
Code:
var delay_ms = 15;
audio_actual_time_ms += delta_time;
audio_play_time_sec = (audio_actual_time - delay) / 1000
audio_sound_set_track_position(audio_play_time_sec);
Disclaimer: I haven't tested this but maybe it'll get you on the right track.
Thanks for a fast reply! I don't know if this is exactly what I'm looking for but this gave me an idea!
 
S

Skible

Guest
If I remember correctly, the current_time variable is the time since system boot in milliseconds. You still won't get a higher precision than one game step, but you could simulate as many actions as would transpire in one game step (in the correct order) to catch up, depending on how often / rarely you expect them to happen (if they're gonna happen CONSTANTLY it might be easier to have 300 frames per second).

Also, you can turn off automatic drawing, which helps you run game logic independently of the drawn frames... could help making 300fps less ridiculous?
I only need this for a couple of sound effects so it is little bit useless to set the fps so high just for that. Also this isn't a crucial element on my game. I think I'm going to play around with the audio_sound_set_track_position function. I hope it understands small enough values.
 
Top