Saving inputtext into a simple text 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Saving inputtext into a simple text file (
/showthread.php?tid=265503)
Saving inputtext into a simple text file -
[SAP]HighFlyer - 01.07.2011
Hello there,
I was wondering how to use File Functions to save inputtext into a text file. What I am trying to do is OnDialogResponse, when the player puts his text into an Input type dialog, the information will get submitted into a text file, creating a new line for each new input. I did some research and I found it's possible, but I'm not sure how to code it, I looked upon file functions and tried something like this:
Код:
if(dialogid == REQUEST && response)
{
new File:pos=fopen("/RadioRequests.txt", io_write);
fwrite(pos, inputtext);
fclose(pos);
}
There's no errors, so I figured out it can't be a brackets issue or anything, it must be that useless format I made. Please could I have some sort of example or correction on how to do that?
Regards,
HighFlyer
Re: Saving inputtext into a simple text file -
Sascha - 01.07.2011
hi HF^^
pawn Код:
if(dialogid == REQUEST && response)
{
new string[256];
if(!fexist("RadioRequests.txt"))
{
new File:create = fopen("RadioRequests.txt", io_write);
fclose(create);
}
format(string, sizeof(string), "%s\r\n", inputtext);
new Fike:pos=fopen("RadioRequests.txt", io_append);
fwrite(pos, string);
fclose(pos);
}
Re: Saving inputtext into a simple text file -
Lorenc_ - 01.07.2011
pawn Код:
stock AddLogLine( field[ ], file[ ], input[ ] )
{
new string[128];
format(string, 128, "%s: %s\r\n", field, input);
new File:fhandle;
if(fexist(file)) {
printf("Creating file '%s' because theres no file created with that name.", file);
}
fhandle = fopen(file,io_append);
fwrite(fhandle,string);
fclose(fhandle);
return 1;
}
Try this, just created one.. change the parameters to desired settings.
Re: Saving inputtext into a simple text file -
BigETI - 01.07.2011
pawn Код:
stock WriteLog(file[], input[])
{
File:filevar;
if(!fexist(file)) filevar = fopen(file, io_write);
else filevar = fopen(file, io_append);
if(!fexist(file))
{
printf("Failed to load '%s'", file);
return 0;
}
else
{
new str[512];
format(str, sizeof(str), "%s\r\n", input);
fwrite(filevar, input);
fclose(filevar);
return 1;
}
}