[Y-INI] My function aint working how it should :S
#1

Hey i made a function that adds lines and basicly it loggs files though its not really doing what it should do..

pawn Код:
stock AddLogLine(playername[], filename[], input[])
{
    new
        string[128]
    ;
    new
        INI:ini = INI_Open(filename)
    ;
    format(string, sizeof(string), "%s\n\n", input);
    INI_WriteString(ini, playername, string);
    INI_Close(ini);
}
So basicly when i use this function on a command it writes the stuff but it usally replaces the current string inside the file wtf lol..

E.G

I done /bug apples...

Prints:
Lorenc = apples

After, retype the cmd /bug, i put a different word.

/bug cool, it replaces apples with cool, anyway i can just create a new line and keep writing the strings like a normal one does, thx.
Reply
#2

Thats how INI files work... Key=Value.
If the Key already exists, it replaces the value with the new value.
Reply
#3

And, how do i prevent that?
Reply
#4

What's the point of using y_ini for logs?
Reply
#5

This is pretty simple to do with native file functions, you don't need y_ini for it.

pawn Код:
stock AddLogLine( player[ ], file[ ], input[ ] )
{
    new
        File: fhandle, // Create a file handler
        tmpstring[ 128 ] // Temperory string to format data.
    ;

    if( !fexist( file ) ) // If the file doesn't exist
    {
        print( "Serv: File did not exist and has been created." ); // Send a friendly message
    }
   
    fhandle = fopen( file, io_write ); // Open the file
    format( tmpstring, sizeof( tmpstring ), "%s:%s\r\n", player, input ); // Format the data
    fwrite( fhandle, tmpstring ); // Write the data to the file
   
    fclose( fhandle ); // Close the file
    return 1;
}
Untested.
Reply
#6

ooh lol, I thought why not yini? its a fast file system anyway, ill make it my self thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)