LoadObjectsFromFile Needed ! Get IN !
#1

Hey,
I Need a function wich will load all of my objects from a ini file.

I saw this function -
Код:
stock LoadObjectsFromFile(const filename[])
{
        new Objects_loaded;
        if(!fexist(filename))
        return printf("[Objects] Couldn't load objects from %s [Reason : File doesn't exist]", filename);

        new File:Handler = fopen(filename, io_read);
        if(!Handler) return printf("[Objects] Couldn't load objects from %s [Reason : I/O Error]", filename);

        new Line[256], Index = -1, Model, Float:PosX, Float:PosY, Float:PosZ, Float:RotX, Float:RotY, Float:RotZ,Float:DrawDistance;
        Objects_loaded = 0;
        while(fread(Handler, Line))
        {
        Index++;
                new EOL = strfind(Line, ";", false);
                if(EOL != -1) strdel(Line, EOL - 1, sizeof Line - 1);
        else
                {
                        printf("[Objects] Error reading @LineIndex %i from %s (EOL not found)", Index, filename);
                        continue;
                }
                if(!sscanf(Line[13], "p<,>iffffffF(100)", Model, PosX, PosY, PosZ, RotX, RotY, RotZ, DrawDistance))
                {
                CreateObject(Model, PosX, PosY, PosZ, RotX, RotY, RotZ, DrawDistance);
                Objects_loaded++;
        }
        else printf("[Objects] Error reading @LineIndex %i from %s (Invalid format)", Index, filename);
     }
        fclose(Handler);
    printf("[Objects] Loaded %d objects from: %s", Objects_loaded, filename);
    return true;
}
But it dont work for me.
I've printed the poses from that function and it loads only : "0.00000" for everthing(Object Model,FloatX and so..).
Reply
#2

Heres is your problem right here "Line[13]" you using sscanf on only one array value in your string if you only want from that part of your string on wards you'll need to use strmid like this I believe.

strmid(line,line,13,256,256);
Reply
#3

I didnt undrstand...
Can you fix that function for me ?

Thank you very much for your comment
Reply
#4

Can you post a few lines of the file you are trying to read thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)