Im usless with c-script, so I hope you after a lite-c result.
USAGE: (TESTED)
ALWAYS needs to called with VAR variables in all 3 parameters.
First call starts the timer, second call stops it and injects the elapsed time into the 3 var parameters.
IF there are values in the parameters VARs as first-call, these are used as a starting-point by the timer.
So you can do
var HH=0, MM=0, SS=0;
StopWatch(HH, MM, SS); //timer started at ZEROs
...
StopWatch(HH, MM, SS); //Stop timer and HH, MM, SS = elapsed time
StopWatch(HH, MM, SS); //Restart timer at HH, MM, SS elapsed time (NO time lost)
...
StopWatch(HH, MM, SS); //Stop timer and HH, MM, SS = elapsed time
STOPWATCH Function itself
void StopWatch(var* Hours, var* Minutes, var* Seconds)
{
static var hours, minutes, seconds, running=0;
if(running==0)
{ //START StopWatch
running = 1;
hours=*Hours; minutes=*Minutes; seconds=*Seconds;
while(running)
{
wait(1);
seconds += (timer()/1000000);
if(seconds>=60)
{
minutes += integer(seconds/60);
seconds = cycle(seconds,0,60);
if(minutes>=60)
{
hours += integer(minutes/60);
minutes = cycle(minutes,0,60);
}
}
}
return;
}
//STOP StopWatch
*Hours = hours; *Minutes = minutes; *Seconds = seconds;
running=0;
return;
}
If this is needed in C-script, I'll need you to let me know, and I'll need more time...