Can't write to file...
#1

Hello there!

I Have activity system, that keeps log from a player, like used admin commands for target player. It uses the basic I/O system, but something might be wrong in my code. I Use "io_write", when activity file does not exist and "io_append", when activity file exists. The problem is this: it won't write to a new line, it keeps replacing the old activity from a ".log" file. Below you can see the current code:

pawn Код:
// Sets the player activity:
            format(string, sizeof(string), "%s.log", PlayerName(ID));
            new File:activity;
            if(!fexist("%s.log"))
            {
                activity = fopen(string, io_write);
            }
            else
            {
                activity = fopen(string, io_append);
            }
            if(activity )
            {
                format(string, sizeof(string), "Hello %s!", PlayerName(ID));
                fwrite(activity , string);
                fwrite(activity , "\r\n");
                fclose(activity);
            }
I Have tried to change multiple things, but nothing. Thanks for your reply in advance!
Reply
#2

Have you tried
pawn Код:
format(string, sizeof(string), "Hello %s!\r\n", PlayerName(ID));
fwrite(FileName, string);
Reply
#3

Quote:
Originally Posted by MikeLovesToHelp
Посмотреть сообщение
Have you tried
pawn Код:
format(string, sizeof(string), "Hello %s!\r\n", PlayerName(ID));
fwrite(FileName, string);
If you look at above, you can see it writes the new line with "\r\n". I Try your method, but I'm sure I Have tried this before and it did not work.

EDIT: Still keeps replacing the file logs.
Reply
#4

pawn Код:
format(string, sizeof(string), "%s.log", PlayerName(ID));
            new File:activity;
            if(!fexist("%s.log"))
Unless you want the file name to be called "%s.log", I recommend formatting your file handle.
Reply
#5

Quote:
Originally Posted by Revo
Посмотреть сообщение
pawn Код:
format(string, sizeof(string), "%s.log", PlayerName(ID));
            new File:activity;
            if(!fexist("%s.log"))
Unless you want the file name to be called "%s.log", I recommend formatting your file handle.
Good point, Revo. I Try that later today.

EDIT: Problem solved, thanks goes to Revo.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)