SA-MP Forums Archive
Format formats numbers differently on Linux than Windows - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Format formats numbers differently on Linux than Windows (/showthread.php?tid=520894)



Format formats numbers differently on Linux than Windows - [WSF]ThA_Devil - 20.06.2014

Baiscly, I have a race script, when player finishes, it converts tick count to readable form:
On windows:
0:45.43
On linux:
0: 4.54

using:
Код:
new ReturnTime[10],minutes,seconds;
	minutes = floatround(ticks/60000,floatround_round);
	ticks = ticks - (60000 * minutes);
	seconds = floatround(ticks/1000);
	ticks = ticks - (1000 * seconds);
	format(ReturnTime,sizeof(ReturnTime),"%2d:%2d.%2d",minutes,seconds,ticks);
	return ReturnTime;



Re: Format formats numbers differently on Linux than Windows - Jefff - 20.06.2014

pawn Код:
new ReturnTime[10],minutes,seconds;
minutes = (ticks / 60000);
seconds = (ticks / 1000) % 60;
ticks = ticks % 1000;
format(ReturnTime,sizeof(ReturnTime),"%02d:%02d.%03d",minutes,seconds,ticks);
return ReturnTime;



Re: Format formats numbers differently on Linux than Windows - [WSF]ThA_Devil - 20.06.2014

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
new ReturnTime[10],minutes,seconds;
minutes = (ticks / 60000);
seconds = (ticks / 1000) % 60;
ticks = ticks % 1000;
format(ReturnTime,sizeof(ReturnTime),"%02d:%02d.%03d",minutes,seconds,ticks);
return ReturnTime;
Doesn't work. That makes it even worse:
0:00.454


Re: Format formats numbers differently on Linux than Windows - Jefff - 20.06.2014

It works but you are using it wrong


Re: Format formats numbers differently on Linux than Windows - Konstantinos - 20.06.2014

Keep in mind that "ticks" is supposed to be in milliseconds for it to work well.


Re: Format formats numbers differently on Linux than Windows - [WSF]ThA_Devil - 20.06.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Keep in mind that "ticks" is supposed to be in milliseconds for it to work well.
I know that. The problem is, the same code, that works in Windows, does not work on linux.


Re: Format formats numbers differently on Linux than Windows - Konstantinos - 20.06.2014

The only problem I could think of is the one wiki mentions that it could cause problems on servers with uptime of over 24 days but that clearly not the problem. Try debugging it and see what values returns.


Re: Format formats numbers differently on Linux than Windows - [WSF]ThA_Devil - 20.06.2014

[21:11:31] ticks - 430
[21:11:31] minutes - 0
[21:11:31] seconds - 0
[21:11:31] ticks left - 430

hmm. Actually it looks that tickcount (on linux ) returns 10th/s rather than milliseconds.

Can anyone else confirm that?

This is what I've got:
Код:
[21:33:59] GetTickCount - 60928
[21:33:59] tickcount - 1120
[21:33:59] GetTickCount - 61131
[21:33:59] tickcount - 1120
[21:33:59] GetTickCount - 61334
[21:33:59] tickcount - 1120
[21:33:59] GetTickCount - 61538
[21:33:59] tickcount - 1120
[21:34:00] GetTickCount - 61742
[21:34:00] tickcount - 1130
[21:34:00] GetTickCount - 61946
[21:34:00] tickcount - 1130
[21:34:00] GetTickCount - 62149
[21:34:00] tickcount - 1130
[21:34:00] GetTickCount - 62352
[21:34:00] tickcount - 1130
[21:34:00] GetTickCount - 62556
[21:34:00] tickcount - 1130
[21:34:01] GetTickCount - 62760
[21:34:01] tickcount - 1140
[21:34:01] GetTickCount - 62964
[21:34:01] tickcount - 1140
[21:34:01] GetTickCount - 63167
[21:34:01] tickcount - 1140
[21:34:01] GetTickCount - 63371
[21:34:01] tickcount - 1140
[21:34:01] GetTickCount - 63574
[21:34:01] tickcount - 1140
[21:34:02] GetTickCount - 63779
[21:34:02] tickcount - 1150
[21:34:02] GetTickCount - 63984
[21:34:02] tickcount - 1150
[21:34:02] GetTickCount - 64187
[21:34:02] tickcount - 1150
[21:34:02] GetTickCount - 64390
[21:34:02] tickcount - 1150
[21:34:02] GetTickCount - 64594
[21:34:02] tickcount - 1150
[21:34:03] GetTickCount - 64800
[21:34:03] tickcount - 1150
[21:34:03] GetTickCount - 65004
[21:34:03] tickcount - 1150
[21:34:03] GetTickCount - 65207
[21:34:03] tickcount - 1160
[21:34:03] GetTickCount - 65411
[21:34:03] tickcount - 1160
[21:34:03] GetTickCount - 65614
[21:34:03] tickcount - 1160
[21:34:04] GetTickCount - 65819
[21:34:04] tickcount - 1170
[21:34:04] GetTickCount - 66022
[21:34:04] tickcount - 1170
[21:34:04] GetTickCount - 66225
[21:34:04] tickcount - 1170
It appears that https://sampwiki.blast.hk/wiki/Tickcount on linux is broken.
Gotta switch to GetTickCount then.