Saving to a 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: Saving to a file (
/showthread.php?tid=564917)
Saving to a file -
KingyKings - 23.02.2015
This is a tricky part of scripting for me.
I will try and explain it the best i can.
SO.
When i type /createquest <questname> It will create a .txt file of the name. I have done that part here.
Код:
CMD:createquest(playerid, params[])
{
new string[128];
if(isnull(params)) return SendClientMessage(playerid, COLOR_RED1, "ERROR: /createquest <questname>");
{
format(string, sizeof(string), "Your quest will be saved as %s.txt", params);
SendClientMessage(playerid, COLOR_RED1, string);
format(savestring, sizeof(savestring), "%s.txt", params);
new File:ftw=fopen(savestring, io_write);
ShowPlayerDialog(playerid, DIALOG_START, DIALOG_STYLE_LIST, "Create Quest", "Quest Name\nQuest Start Position\nEnd Position\nSave", "Done", "Cancel");
return 1;
}
}
Thats great. That works fine and it creates the file. The only problem i have is that i do not know how i can add text to that file.
As it works through a dialog system. I want it so the text file is created. When someone types in the Quest name from another dialog, it will add it to the Text file.
Код:
if(dialogid == DIALOG_NAME)
{
if(!response) //
{
SendClientMessage(playerid, COLOR_RED1, "You didn't set a name");
}
else
{
new string[128];
new namestring[128];
format(string, sizeof(string), "You named your Quest: %s", inputtext);
SendClientMessage(playerid, COLOR_RED1, string);
format(namestring, sizeof(namestring), "QuestName: %s", inputtext);
new File:ftw=fopen(savestring, io_append);
fwrite(ftw, namestring);
return 1;
}
So what i have done here is. Create a dialog that asks for text input for a name.
Because the file FTW has been created under a command, it is not available to use under any other public. So on that part of code i have attempted to "Re open" the file and write in it. However that doesn't seem to work.
PS The reason why i did
Код:
new File:ftw=fopen(savestring, io_write);
underneath the CMD is because i want to be able to change the name of the text file when i first create it. E.G /createquest questname which will save as questname.txt
I hope i made sense and i would appreciate it if you guys could help or atleast try.
Re: Saving to a file -
Matess - 23.02.2015
What about adding fclose when you finish editing of your file?
Re: Saving to a file -
KingyKings - 23.02.2015
Wow... just that little thing worked. Thanks so much