File doesn't save (.cfg) - 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: File doesn't save (.cfg) (
/showthread.php?tid=602888)
File doesn't save (.cfg) -
nerovani - 14.03.2016
This is my code:
Код:
enum PhoneInf
{
nNumber
};
new PhoneInfo[200][PhoneInf];
public OnFilterScriptExit()
{
SavePhones();
return 1;
}
stock SavePhones()
{
new idx = 1, File:file;
new string[256];
while(idx < 200)
{
format(string, sizeof(string), "%d\r\n",PhoneInfo[idx][nNumber]);
if(idx == 1)
{
file = fopen("phones.cfg", io_write);
}
else
{
file = fopen("phones.cfg", io_append);
}
fwrite(file, string);
fclose(file);
idx++;
}
}
It all works great while the server is online. I even went to check if SavePhones(); works correctly by adding it in the middle of the script and the .cfg file looked just as I want.
But the main problem and the only problem is that all the data after the filterscript/server gets reset is set to 0. And all I get in the .cfg after the reloading of the filterscript is "0" and more "0".
The data somehow gets dumped after the filterscript is reloaded, like it just disapears.
Re: File doesn't save (.cfg) -
czerwony03 - 14.03.2016
Add:
while writing.
But i would like to suggest you, creating one string with
and executing fwrite once....