SA-MP Forums Archive
Question about dini - 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: Question about dini (/showthread.php?tid=312904)



Question about dini - milanosie - 23.01.2012

Hello, I have a question about the use of DINI..

Please dont start moaning that DINI is slow etc...
I just want awnser on this question if possible

So, Lets say:

I have a folder called blabla

Then I have files in it caller

1.ini
2.ini
etc...

Now. How do I make it so, that on the command/function im using it creates the next .ini

example:

5.ini exists.. It have to make a file called 6.ini

If 6.ini exists... it have to make a file called 7.ini

etc.


Is this possible? and if yes, how?

thanks


Re: Question about dini - ricardo178 - 23.01.2012

Hum... I guess he didn't understand you ******.. I also can't understand, your knowledge is like 1000 times superior...

By the way, i guess you are talking about this when calling "fexist"...

Код:
if(fexist(file))
{
    
}
Like you do in register/login system.
By the way, i don't understand how to create next one... You need some function to check the number, and create the next one.


Re: Question about dini - milanosie - 23.01.2012

Quote:

Yes, but not using dini directly, you would just need to loop through numbers and call "fexist" on each one (with ".ini" appended to each number). This is, however, VERY inefficient as you need to query the hard disk for ever single file (which can take a LONG time if you have lots of files).

Ok, I do understand that part, and the bottom a little.
Just, How would I make the index then?
I might have an idea, but as I am relatively new to scripting(bout 2-3 weeks) I am not completely sure.
Could you give me your opinion on this?

ofcourse, this is not detailed or something, Since I will have to think about how to make this.
But is this going the right way? or is itcompletly wrong?
pawn Код:
enum Vindex
{
    topnumber,
}

new Index[Vindex];
format(file,sizeof(file),"realityrp/vehicles/Vindex.ini");
    if (!dini_Exists(file))
    {
        dini_Create(file);
        dini_IntSet(file, "topnumber",Index[topnumber] = 0);
    }
    if(fexist(file))
    {      
        dini_IntSet(file, "topnumber",Index[topnumber] = topnumber + 1);
    }



Re: Question about dini - Konstantinos - 23.01.2012

pawn Код:
CMD:create( playerid, params[ ] )
{
    new
        File1[ 20 ], File2[ 20 ], File1Msg[ 23 ], File2Msg[ 23 ];

    if( sscanf( params, "s[20]s[20]", File1, File2 ) ) return SendClientMessage( playerid, -1, "Usage: /create <File1> <File2>" );
    format( File1Msg, sizeof( File1Msg ), "%s.ini", File1 );
    format( File2Msg, sizeof( File2Msg ), "%s.ini", File2 );

    if( fexist( File1Msg ) ) // if File 1 exists, create the Second.
    {
        dini_Create( File2Msg );
        dini_IntSet(File2Msg, "Something...HERE", 0); // An example
    }
    return 1;
}



Re: Question about dini - milanosie - 23.01.2012

Quote:
Originally Posted by Dwane
Посмотреть сообщение
pawn Код:
CMD:create( playerid, params[ ] )
{
    new
        File1[ 20 ], File2[ 20 ], File1Msg[ 23 ], File2Msg[ 23 ];

    if( sscanf( params, "s[20]s[20]", File1, File2 ) ) return SendClientMessage( playerid, -1, "Usage: /create <File1> <File2>" );
    format( File1Msg, sizeof( File1Msg ), "%s.ini", File1 );
    format( File2Msg, sizeof( File2Msg ), "%s.ini", File2 );

    if( fexist( File1Msg ) ) // if File 1 exists, create the Second.
    {
        dini_Create( File2Msg );
        dini_IntSet(File2Msg, "Something...HERE", 0); // An example
    }
    return 1;
}
Where is this about? this is not really what i mean, since as ****** said, this loops trough all files right?


Re: Question about dini - milanosie - 23.01.2012

hmm might know it.. will post when I see if it works


Re: Question about dini - Konstantinos - 23.01.2012

Quote:
Originally Posted by milanosie
Посмотреть сообщение
Where is this about? this is not really what i mean, since as ****** said, this loops trough all files right?
You said by command to check if for example 5.ini exists to create 6.ini
/create 5 6

If 5.ini file exists it creates the name you gave on the command. In that case, it will create 6.ini
Or I understood wrong?


Re: Question about dini - milanosie - 23.01.2012

Quote:
Originally Posted by Dwane
Посмотреть сообщение
You said by command to check if for example 5.ini exists to create 6.ini
/create 5 6

If 5.ini file exists it creates the name you gave on the command. In that case, it will create 6.ini
Or I understood wrong?
yep, but thanks anyway Will post when im done if I have any errors left


Re: Question about dini - milanosie - 23.01.2012

something like this?

pawn Код:
format(file9,sizeof(file9),"realityrp/vehicles/Vindex.ini");
dini_IntSet(file9, "topnumber",Index[topnumber] = Index[topnumber] + 1);
format(file4,sizeof(file3), "realityrp/vehicles/%d.ini", Index[topnumber] + 1);
dini_Create(file4);
dini_IntSet(blablablabla....



Re: Question about dini - SchurmanCQC - 23.01.2012

The following code is to check for files that exist:
pawn Код:
#define MAX_FILES 1000
......
for(new f=0; f < MAX_FILES; f ++)
{
    new fileName[25]; format(fileName, 25, "%d.ini", f);
    if(dini_Exists(fileName))
    {
       //Do something here.
    }
    else
    {
        continue;
        //OR
        break;
        //Continue or break is based on your personal preference.
    }
}
This code is to check if the file doesn't exist:
pawn Код:
#define MAX_FILES 1000
......
for(new f=0; f < MAX_FILES; f ++)
{
    new fileName[25]; format(fileName, 25, "%d.ini", f);
    if(!dini_Exists(fileName))
    {
       //Do something here, then call break; to make sure you don't spit out 5000000 files repeatedly.
       break;
    }
    else
    {
        continue;
    }
}
EDIT: Am I the only one that posted correct code?