SA-MP Forums Archive
A tag mismatch - 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: A tag mismatch (/showthread.php?tid=430117)



A tag mismatch - thefatshizms - 12.04.2013

Hello, I'm getting a tag mismatch with this:

pawn Код:
while( fread(filehandle, line) )
I have looked on the wiki and it seems to be the correct syntax..


Re: A tag mismatch - KingHual - 12.04.2013

Are you sure your handle variable has the File tag?


Re: A tag mismatch - FunnyBear - 12.04.2013

This should somehow give you an idea,

pawn Код:
new line[128]; //A string a 128 string cell (depending on the size of your file, change it)
    new File:filehandle = fopen("" /* << .txt file location/name */, io_read); // this will open the file
    while(fread(filehandle, line)) // This will read the file
    {
        // Your code here
    }
    fclose(filehandle); // Closes the file
Maybe you forgot the File: in the filehandle variable. It will be easier if you can give more code.


Re: A tag mismatch - thefatshizms - 12.04.2013

Yep.

Function where I'm getting the tag mismatch:
pawn Код:
stock INI_GetInt(filehandle, Key[], &dest) {

    new pos, line[MAX_FILE_STRING];
   
    while( fread(filehandle, line) ) {
   
        if( (pos = strfind(line, Key, false)) != -1 ) {//-1 would be not found
       
            new idx = pos + strlen(Key) + 1;
           
            if(line[idx] == ' ') {//the value is nothing
           
                idx = pos + strlen(Key) + 2;//if the = sign is further across
               
                if(idx > strlen(line)) return -1; //there was no value found
               
                dest = (idx < sizeof(line)) ? strval(line[idx]) : 0;
                return 1;
            }
           
            dest = (idx < sizeof(line)) ? strval(line[idx]) : 0;
            return 1;
        }
   
    }
    return 0;
}
how i'm testing it:

pawn Код:
new File:Myfile = fopen("MyFile.ini", io_read), myscore;
INI_GetInt(Myfile, "score", myscore);
fclose(Myfile);



Re: A tag mismatch - KingHual - 12.04.2013

You need to add a File tag to filehandle

Код:
stock INI_GetInt(File:filehandle, Key[], &dest) {

    new pos, line[MAX_FILE_STRING];
    
    while( fread(filehandle, line) ) {
    
        if( (pos = strfind(line, Key, false)) != -1 ) {//-1 would be not find
        
            new idx = pos + strlen(Key) + 1;
            
            if(line[idx] == ' ') {//the value is nothing
            
                idx = pos + strlen(Key) + 2;//if the = sign is further across
                
                if(idx > strlen(line)) return -1; //there was no value found
                
                dest = (idx < sizeof(line)) ? strval(line[idx]) : 0;
                return 1;
            }
            
            dest = (idx < sizeof(line)) ? strval(line[idx]) : 0;
            return 1;
        }
    
    }
    return 0;
}
That should fix it


Re: A tag mismatch - FunnyBear - 12.04.2013

Ahhaha, found the prob you forgot to add File: to the top of your function title before filehandler just like how you are testing it

EDIT: Shit someone already posted first.


Re: A tag mismatch - thefatshizms - 12.04.2013

Ahh thanks

I forgot that you had to add tags within the function params