AMX backtrace -
Youssef221 - 13.11.2014
why does it show me these things: [15:24:17] [debug] AMX backtrace:
[15:24:17] [debug] #0 native PrintAmxBacktrace () [b74bb640] from crashdetect.so
[15:24:17] [debug] #1 0004104c in public TimeU () from LSGW.amx
in my server logs,
maybe those are doing this?:
pawn Code:
forward TimeU();
public TimeU()
{
new string[7];
Tsec+=1;
if(Tsec==60) {
Tsec=00;
THrs+=1;
}
if(THrs==24) {
Tsec=00;
THrs=0;
}
if(Tsec<10) {
format(string,sizeof(string),"%d:%d0",THrs,Tsec);
}
if(Tsec>10) {
format(string,sizeof(string),"%d:%d",THrs,Tsec);
}
if(THrs<10) {
//formats string
format(string,sizeof(string),"0%d:%d",THrs,Tsec);
}
for___loop(new i; i<MAX_PLAYERS; i++) {
if(IsPlayerConnected(i)) {
SetPlayerTime(i,THrs,Tsec);
}
}
TextDrawSetString(Servt,string);
return 1;
}
, please help
Re: AMX backtrace -
Kwarde - 13.11.2014
I'm focusing on something else;
pawn Code:
Tsec+=1;
if(Tsec==60) {
Tsec=00;
THrs+=1;
}
if(THrs==24) {
Tsec=00;
THrs=0;
}
I recommend you to use "if (Tsec >= 60)" and "if (trs >= 24)". I had a weird bug sometime, which made the "Tsec" from 59 to 61 (the 60 was passed or just not checked). And because "Tsec" was not "60", it kept counting the seconds (at some point, the time was "HH:MM:506"
Also, I assume you want the GTA SA speed style (looking at this), since it
pawn Code:
if(Tsec<10) {
format(string,sizeof(string),"%d:%d0",THrs,Tsec);
}
if(Tsec>10) {
format(string,sizeof(string),"%d:%d",THrs,Tsec);
}
if(THrs<10) {
//formats string
format(string,sizeof(string),"0%d:%d",THrs,Tsec);
}
So, this would be the outputs:
Tsec = 0: %d:00
Tsec = 1: %d:10
Tsec = 2: %d:20
Tsec = 3: %d:30
Tsec = 4: %d:40
Tsec = 5: %d:50
Tsec = 6: %d:60
Tsec = 7: %d:70
Tsec = 8: %d:80
Tsec = 9: %d:90
Tsec = 10: --Nothing, since you didn't 'tell' the script what to do when Tsec is 10--
Tsec = 11: %d:11
Tsec = 12: %d:12
Tsec = 13: %d:13
etc. You sure you don't want "01, 02, 03 etc"? (just like with THrs).
You don't have to do it this way though (checking the value and than either formatting "%d" or "0%d". If you want to format a 2-digit integer (00, 01, 02, 10, 34 etc), you can simply use
%02d.
pawn Code:
new hour = 6;
new minute = 34;
new second = 2;
new mSecond = 984; //milliseconds
new formatString1[15];
new formatString2[15];
format(formatString1, 15, "%d:%d:%d:d", hour, minute, second, mSecond); //Yes, it's a waste of space and memory to use a string while I could simply directly use printf. This is just an example of %d and %02d, and this makes it better readable I think
format(formatString2, 15, "%02d:%02d:%02d:%02d", hour, minute, second, mSecond);
printf("formatString1 = %s", formatString1);
printf("formatString2 = %s", formatString2);
This would print in the client:
Code:
formatString1 = 6:34:2:984
formatString2 = 06:34:02:984
You could also use
%03d,
%04d etc.
pawn Code:
new value = 3;
new formatString[6];
format(formatString, 6, "%05d", value);
printf("formatString = %s", formatString);
//Would print: formatString = 00005
Here's your script again, the way I'd do it (except for player loop) (not fixing the problem you asked for, but just the way I'd use) - Consider using it, or atleast learn from it
pawn Code:
forward TimeU();
public TimeU()
{
new string[7];
Tsec++; //Since '++' does precisely the same as '+= 1'. I prefer using ++ for this;
if (Tsec > 59)
{
Tsec = 0;
THrs++;
if (THrs > 23) THrs = 0; //Not needed to set the seconds to zero again. If Tsec = 59, then Tsec becomes 0 and THrs becomes 'THrs + 1'. Why would you set a value to zero while it is already zero?
}
//I put the THrs check within the second check; THrs can only change when TSec >= 60 (>59), so it is a waste to check THrs all the time.
format(string, sizeof(string), "%02d:%02d", THrs, TSec);
for___loop(new i; i<MAX_PLAYERS; i++) {
if(IsPlayerConnected(i)) {
SetPlayerTime(i,THrs,Tsec);
}
}
TextDrawSetString(Servt,string);
return 1;
}