stock WriteLog(file[], text[])
#1

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.
Reply
#2

How are you using WriteLog?
Also, why are you creating and formatting a string to print something on the console? Use printf instead.
Reply
#3

WriteLog("log/loading", "text");
Reply
#4

Either use this:
WriteLog("scriptfiles/log/loading", "text");

Or modify this in WriteLog:
format(fileText, 126, "scriptfiles/%s.txt", file);
Reply
#5

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.
Reply
#6

It's windows.
Reply
#7

You can't read files from outside of scriptfiles.
Reply
#8

It's not outside scriptfiles, I got a folder in scriptfiles called logs, But it wont append, It gives me the error at print.
Reply
#9

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)