fopen problem
#1

Wow i am a dang noob.... i cannot figure out how to read from a file then write a value to an existing line of text...
I am trying to make a faction and have the faction be 1 for the gang in the players profile but i cannot figure it out... the compiler`s library crashes everytime i compile... this is the problem area:

Код:
new checkpoint1;
new string[128],sendername[128];
GetPlayerName(newsz,sendername,sizeof(sendername));
format(string,sizeof(string), "ladmin/%s.save", sendername);
new File:news = fopen(string,io_write)
I am trying to make it so it writes to the existing file News = 0 but i cannot figure out how, this looks like it will write it anywhere....


I am such a scripting newb
Reply
#2

when you open a file, you should check if the operation was successful before fwriting / freading. This is because there will be an error if you try to perform file operations on a file that was never opened.
pawn Код:
new File:news = fopen(string,io_write); // don't forget the semicolan
if(news)
{
    //rest of file operations here
     fclose(news);
}
the 'io_write' operation will clear a file and write in it as if it were a new file, so you can't just write one selected line to the file, you have to write the entire contents of the file again.

You can however use 'io_append' which will leave the file intact, and anything written will be added to the end of the file.
Reply
#3

Are you a good scripter? if so can you help me understand some of it a bunch more? I will try this thanks


BTW when i type in "fopen(" it does not show a tool tip saying the params... so is that a problem?


Nope.... It closes my server connection when it tries to connect.... can someone help me?
Reply
#4

I am not a very good scripter.

I taught myself to script with trial and error, looking at the native functions in the pawno tab, and using ****** ( aka the wiki).

eg if you ****** 'samp fopen' it will lead you here.
https://sampwiki.blast.hk/wiki/Fopen

Then when I got really stuck I either made a thread in this forum, or asked in irc.sa-mp.com #sa-mp.scripting
Reply
#5

I am so retarted i cant do anything right, i edited my previous post....

i cannot figure this out
Reply
#6

pawn Код:
format(string,sizeof(string), "ladmin/%s.save", sendername);
make the size of your sendername MAX_PLAYER_NAME ( smaller )
make sure there is a 'ladmin' folder in your scriptfiles folder.
try changing the file extension to .cfg, or .ini
make sure you check the file has been opened before writing anything to it.
don't forget the ';' after the fopen command
pawn Код:
new string[128],sendername[MAX_PLAYER_NAME];

...
format(string,sizeof(string), "ladmin/%s.cfg", sendername);
new File:news = fopen(string,io_write);
if(news)
{
     // you will need to put your file operations here
     fclose(news);
}
Reply
#7

This will not help, as i am trying to promote one person using /givenews <PLAYERID> so i have to set sendername as 128.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)