A tag mismatch
#1

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..
Reply
#2

Are you sure your handle variable has the File tag?
Reply
#3

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.
Reply
#4

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);
Reply
#5

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
Reply
#6

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.
Reply
#7

Ahh thanks

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


Forum Jump:


Users browsing this thread: 1 Guest(s)