17.09.2012, 18:25
You could always add line-by-line debugging to see where things go sour and it crashes, for example:
My best guess is that you are not checking if the file pointer is valid (the file may not exist in the scriptfiles folder or sa-mp server executable might not have access to it, etc). You can check this by doing:
Also, read the documentation for these natives: https://sampwiki.blast.hk/wiki/Fopen https://sampwiki.blast.hk/wiki/Fclose https://sampwiki.blast.hk/wiki/Fwrite
The wiki might have some information about common pitfalls.
... this is perfectly valid code. But is it beneficial? In most cases, no.
In the current case, I see he does not do much, in fact:
Could easily become:
pawn Код:
print("fopen");
playerinfos = fopen(...);
print("fwrite");
fwrite(...);
print("fclose");
fclose(...);
pawn Код:
playerinfos = fopen("playerinfos.txt", io_write);
if(playerinfos) // Check if the file handle is valid!
{
fwrite(playerinfos, pntFinal);
fclose(playerinfos);
}
The wiki might have some information about common pitfalls.
Quote:
You are using "format" twice which is actually useless because you are formatting the same thing then erasing the old and re-formatting it again.
So just format then append your changes. Then format again. |
pawn Код:
format(string, sizeof(string), "Hey, %s!", szSomething);
format(string, sizeof(string), "%s|Oh hello there!", string);
In the current case, I see he does not do much, in fact:
pawn Код:
format(pntFinal,sizeof(pntFinal),"Name: %s | ",pntName);
format(pntFinal,sizeof(pntFinal),"%sIP: %s | ",pntFinal,pntIp);
pawn Код:
format(pntFinal, sizeof(pntFinal), "Name: %s | IP: %s | ", pntName, pntIp);