Milliseconds to HH:MM:SS:MS ?

N

NoFontNL

Guest
Hi, as you read in the title, I'm asking for help with conversion of milliseconds to the hh:mm:ss:ms version.
This is my code now, but it is pretty messed up.
Code:
/// @desc scMsToTime(milliseconds);
/// @arg milliseconds
var milliseconds = argument0;
var ms = ((milliseconds % 1000) / 100),
    seconds = ((milliseconds / 1000) % 60),
    minutes = ((milliseconds / (1000 * 60)) % 60),
    hours = ((milliseconds / (1000 * 60 * 60)) % 24);
if(hours<10) hours="0"+string(hours);
if(minutes<10) minutes="0"+string(minutes);
if(seconds<10) seconds="0"+string(seconds);
if(ms<10) ms="0"+string(ms);
  return string(hours + ":" + minutes + ":" + seconds + "." + ms);
Output > 00.00:00.00:00.00.00.00 // and then it's going up randomly.

Note:
Game FPS: 60;

Create:
theTime=0;

Step:
theTime++;

Draw:
draw_text(x,y,scMsToTime(theTime));

The seconds don't go up by seconds, there's a little delay.

Any help would be appreciated.
 

TheouAegis

Member
Um... You are increasing time by 1 each step. That's A LOT SLOWER than counting by milliseconds, like 17x slower. 1 step takes roughly 17 milliseconds.
 
I

icuurd12b42

Guest
you can pass get_timer()/1000 for ms

you are missing a bunch of floor() calls. that will rid of the extra dots

and you need to string() every number in this line
return string(hours + ":" + minutes + ":" + seconds + "." + ms);
 
N

NoFontNL

Guest
Yeah. In the time nobody replied, I did the sinple equatation.
60 frames = 1 second = 1000 ms.
1 frame = 1000/60 ms.
So I added 1000/60 each step.
 
D

dannyjenn

Guest
Yeah. In the time nobody replied, I did the sinple equatation.
60 frames = 1 second = 1000 ms.
1 frame = 1000/60 ms.
So I added 1000/60 each step.
This works in theory but not in real life. Because even if your game's speed is set to 60, the actual frame rate is most likely going to fluctuate. If you use 1000/60 then you'll end up with a good approximation (at best) or some number that is completely wrong (at worst).

I believe that there is some sort of function or variable to do what you want though, but I don't know its name.
 
I

icuurd12b42

Guest
yeah you want actual game time and not real time

>So I added 1000/60 each step.

yeah!
theTime+=1000/60;

You cannot mix real time, such as fps_real, get_timer, delta_time, or even date_ functions, with game time (time that matches game lag) for user tasks for example...


if you alot the player 1 (real time) minute to complete a task, like reach a position on a map, and he is lagging and running at 30 fps instead of 60 (and the movement does not use deltatime but the default frame based movement), if you use real time for your clock, his time will expire before he reached the halfway point. Also it's hard to implement PAUSE and stop the time if you are not accumulating it yourself


I remember this Space Quest rescue mission in the 90's that I only was able to complete when I upgraded my pc. Same with a Wing Commander game where I had to rescue this ship...
 
Top