Can't write to file... - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Can't write to file... (
/showthread.php?tid=430215)
[SOLVED] Can't write to file... -
CrossUSAAF - 13.04.2013
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!
Re: Can't write to file... -
Isolated - 13.04.2013
Have you tried
pawn Код:
format(string, sizeof(string), "Hello %s!\r\n", PlayerName(ID));
fwrite(FileName, string);
Re: Can't write to file... -
CrossUSAAF - 13.04.2013
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.
Re: Can't write to file... -
Revo - 13.04.2013
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.
Re: Can't write to file... -
CrossUSAAF - 13.04.2013
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.