stock WriteLog(file[], text[]) -
Luicy. - 25.05.2016
So, I just realised that this code don't work really, Here's the code:
pawn Код:
//****||** Log Writing **||****//
stock WriteLog(file[], input[])
{
new fileText[126];
format(fileText, 126, "%s.txt", file);
new File:handle = fopen(fileText, io_append);
if(handle)
{
new H, M, S,
inputText[126];
gettime(H, M, S);
format(inputText, 126, "[%02d:%02d:%02d] %s\r\n", H, M, S, input);
fwrite(handle, inputText);
fclose(handle);
}
else
{
new printText[126];
format(printText, 126, "Could not append to file %s", file);
print("Error at stock WriteLog(file[], input[])");
print(printText);
}
}
stock WritePlayerLog(playerid, input[])
{
new fileText[126],
name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(fileText, 126, "log/%s.txt", name);
new File:handle = fopen(fileText, io_append);
if(handle)
{
new H, M, S,
inputText[126];
gettime(H, M, S);
format(inputText, 126, "[%02d:%02d:%02d] %s\r\n", H, M, S, input);
fwrite(handle, inputText);
fclose(handle);
}
else
{
new printText[126];
format(printText, 126, "Could not append to file %s", name);
print("Error at stock WritePlayerLog(file[], input[])");
print(printText);
}
}
I receive Error at stock ...
at the samp server.
Re: stock WriteLog(file[], text[]) -
Stinged - 25.05.2016
How are you using WriteLog?
Also, why are you creating and formatting a string to print something on the console? Use printf instead.
Re: stock WriteLog(file[], text[]) -
Luicy. - 25.05.2016
WriteLog("log/loading", "text");
Re: stock WriteLog(file[], text[]) -
Stinged - 25.05.2016
Either use this:
WriteLog("scriptfiles/log/loading", "text");
Or modify this in WriteLog:
format(fileText, 126, "scriptfiles/%s.txt", file);
Re: stock WriteLog(file[], text[]) -
Konstantinos - 25.05.2016
Quote:
Originally Posted by Stinged
Either use this:
WriteLog("scriptfiles/log/loading", "text");
Or modify this in WriteLog:
format(fileText, 126, "scriptfiles/%s.txt", file);
|
fopen cannot read from outside scriptfiles anyways so it doesn't matter.
Problems such as that, that file cannot be opened mostly happens in Linux due to the permissions.
Re: stock WriteLog(file[], text[]) -
Luicy. - 25.05.2016
It's windows.
Re: stock WriteLog(file[], text[]) -
Stinged - 25.05.2016
You can't read files from outside of scriptfiles.
Re: stock WriteLog(file[], text[]) -
Luicy. - 25.05.2016
It's not outside scriptfiles, I got a folder in scriptfiles called logs, But it wont append, It gives me the error at print.
Re: stock WriteLog(file[], text[]) -
Stinged - 25.05.2016
Quote:
Originally Posted by Stinged
Either use this:
WriteLog("scriptfiles/log/loading", "text");
Or modify this in WriteLog:
format(fileText, 126, "scriptfiles/%s.txt", file);
|
Then this is the solution.