Saving inputtext into a simple text file
#1

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

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);
}
Reply
#3

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

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;
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)