PDA

View Full Version : tickcount() skips numbers sometimes.


Activest
13/08/2013, 06:58 AM
Hey.
I noticed that GetTickCount() skips sometimes numbers, I think its because the milliseconds.
I want to do race-times, but how to fix that the numbers will be right?
The testing was about 20 seconds, but its finishing on the number 22 instead 20.
I tried to check it with this:

new
Timer,
gStartTime;
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/try", true))
{
Timer = 0;
gStartTime = GetTickCount();
return 1;
}
return 0;
}
forward Update();
public Update()
{
new string[128];
if(Timer < 21)
{
new
totalSeconds = GetTickCount() - gStartTime, minutes, seconds, ms;
timeconvert(totalSeconds, minutes, seconds, ms);
format(string, sizeof(string), "Time: %d minutes, %d seconds and %d ms.", minutes, seconds, ms);
SendClientMessageToAll(-1, string);
}
Timer++;
}
timeconvert(Time, &Minutes, &Seconds, &MSeconds)
{
new Float:fTime = floatdiv(Time, 60000);
Minutes = floatround(fTime, floatround_tozero);
Seconds = floatround(floatmul(fTime - Minutes, 60), floatround_tozero);
MSeconds = floatround(floatmul(floatmul(fTime - Minutes, 60) - Seconds, 1000), floatround_tozero);
}

Pottus
13/08/2013, 07:30 AM
Let me guess...

SetTimer("Update", 1000, true);

Activest
13/08/2013, 07:40 AM
Yes :D, but why its matter? if I did the timer for 20 seconds then this is the results(22 and sometimes 23)
Even if I did another variable like Timer++ that displaying the minutes and seconds instead the GetTickCount(),
on the results the GetTickCount() is higher from the number...

Well, how can I accurate the time on messages?

Pottus
13/08/2013, 08:00 AM
It matters because timers in SAMP are not accurate what you think is 1000 (1 - second) is about 1.1 seconds that is why your results are off.

http://forum.sa-mp.com/showthread.php?t=289675