Floats don't load correctly
#1

Hello there,

I have tried a lot to load floats using "File" Data, but what happens is, all the floats loads (0.0000) although they're saved correctly.

pawn Код:
stock LoadBiz()
{
    if(!fexist(PATH)) return 1;

    new File:i=fopen(PATH, io_read), st[1020], idx;
    while(idx < sizeof(BusinessInfo) && fread(i, st))
    {
        sscanf(st, "p<|>iis[32]iiiffffffffiiiis[128]",
            BusinessInfo[idx][bOwned],
            BusinessInfo[idx][bPrice],
            BusinessInfo[idx][bOwner],
            BusinessInfo[idx][bType],
            BusinessInfo[idx][bLocked],
            BusinessInfo[idx][bMoney],
            BusinessInfo[idx][bEntranceX],
            BusinessInfo[idx][bEntranceY],
            BusinessInfo[idx][bEntranceZ],
            BusinessInfo[idx][bEntranceA],
            BusinessInfo[idx][bExitX],
            BusinessInfo[idx][bExitY],
            BusinessInfo[idx][bExitZ],
            BusinessInfo[idx][bExitA],
            BusinessInfo[idx][bInt],
            BusinessInfo[idx][bWorld],
            BusinessInfo[idx][bInsideInt],
            BusinessInfo[idx][bInsideWorld],
            BusinessInfo[idx][bName]
        );
    }
    fclose(i);
    BusinessInfo[idx][bOutsideIcon] = CreateDynamicPickup(1272, 1, BusinessInfo[idx][bEntranceX], BusinessInfo[idx][bEntranceY], BusinessInfo[idx][bEntranceZ], BusinessInfo[idx][bWorld]); //Creates a pickup at the business entrance.
    BusinessInfo[idx][bInsideIcon] = CreateDynamicPickup(1272, 1, BusinessInfo[idx][bExitX], BusinessInfo[idx][bExitY], BusinessInfo[idx][bExitZ], BusinessInfo[idx][bInsideWorld]); //Creates a pickup at the exit(Inside the interior)
    printf("%f|||%f|||%f|||%d", BusinessInfo[idx][bEntranceX], BusinessInfo[idx][bEntranceY], BusinessInfo[idx][bEntranceZ], BusinessInfo[idx][bWorld]);

    print("done");
    return 1;
}
It prints after then (0.000|||0.000|||0.000|||0), I wonder why this is happening?

and In advance, I did a small test, I wonder if I make this problem
pawn Код:
if (strcmp("/savemyhp", cmdtext, true) == 0)
    {
        new pname[32],Float:health, str[200];
        GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
        GetPlayerHealth(playerid, health);
        new File:hp=fopen("/UsersHP.ini", io_append);
        if(hp)
        {
            format(str, sizeof(str), "%s(hp)=%f\r\n", pname, health); fwrite(hp, str);
            fclose(hp);
        }
        return 1;
    }
    if (strcmp("/loadmyhp", cmdtext, true) == 0)
    {
        new File:hp=fopen("/UsersHP.ini", io_read), string[200], str[200];
        fread(hp, str);
        format(string, 200, "The health you saved = %f", floatstr(str));
        SendClientMessage(playerid, -1, string);
        fclose(hp);
        return 1;
    }
It saves well, but it loads quite bad.

Thank you in advance
Reply
#2

That happened to me once. Finally I avoided the problem reading those parameters as strings and then converting them to floats with floatstr.
It isn't the most professional solution, but it works.
Reply
#3

Quote:
Originally Posted by PHudson
Посмотреть сообщение
That happened to me once. Finally I avoided the problem reading those parameters as strings and then converting them to floats with floatstr.
It isn't the most professional solution, but it works.
actually, I did that already,

Код:
format(string, 200, "The health you saved = %f", floatstr(str));
but the same result.
Reply
#4

How are the floats saved in the file?
Reply
#5

Quote:
Originally Posted by Basssiiie
Посмотреть сообщение
How are the floats saved in the file?
Quote:
Originally Posted by TH3_R3D™
Посмотреть сообщение
pawn Код:
if (strcmp("/savemyhp", cmdtext, true) == 0)
    {
        new pname[32],Float:health, str[200];
        GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
        GetPlayerHealth(playerid, health);
        new File:hp=fopen("/UsersHP.ini", io_append);
        if(hp)
        {
            format(str, sizeof(str), "%s(hp)=%f\r\n", pname, health); fwrite(hp, str);
            fclose(hp);
        }
        return 1;
    }
pawn Код:
stock SaveBiz(id)
{
    new File:File=fopen(PATH, io_write);
    if(File)
    {
        new str[165];
        fwrite(File,"[data]\r\n");
        format(str,30,"bOwned=%d\r\n", BusinessInfo[id][bOwned]);               fwrite(File, str);
        format(str,30,"bPrice=%d\r\n", BusinessInfo[id][bPrice]);               fwrite(File, str);
        format(str,30,"bOwner=%s\r\n", BusinessInfo[id][bOwner]);               fwrite(File, str);
        format(str,30,"bType=%d\r\n", BusinessInfo[id][bType]);                 fwrite(File, str);
        format(str,30,"bLocked=%d\r\n", BusinessInfo[id][bLocked]);             fwrite(File, str);
        format(str,30,"bMoney=%d\r\n", BusinessInfo[id][bMoney]);               fwrite(File, str);
        format(str,30,"bEntranceX=%f\r\n", BusinessInfo[id][bEntranceX]);       fwrite(File, str);
        format(str,30,"bEntranceY=%f\r\n", BusinessInfo[id][bEntranceY]);       fwrite(File, str);
        format(str,30,"bEntranceZ=%f\r\n", BusinessInfo[id][bEntranceZ]);       fwrite(File, str);
        format(str,30,"bEntranceA=%f\r\n", BusinessInfo[id][bEntranceA]);       fwrite(File, str);
        format(str,30,"bExitX=%f\r\n", BusinessInfo[id][bExitX]);               fwrite(File, str);
        format(str,30,"bExitY=%f\r\n", BusinessInfo[id][bExitY]);               fwrite(File, str);
        format(str,30,"bExitZ=%f\r\n", BusinessInfo[id][bExitZ]);               fwrite(File, str);
        format(str,30,"bExitA=%f\r\n", BusinessInfo[id][bExitA]);               fwrite(File, str);
        format(str,30,"bInt=%d\r\n", BusinessInfo[id][bInt]);                   fwrite(File, str);
        format(str,30,"bWorld=%d\r\n", BusinessInfo[id][bWorld]);               fwrite(File, str);
        format(str,30,"bInsideInt=%d\r\n", BusinessInfo[id][bInsideInt]);       fwrite(File, str);
        format(str,30,"bInsideWorld=%d\r\n", BusinessInfo[id][bInsideWorld]);   fwrite(File, str);
        format(str,30,"bName=%s\r\n", BusinessInfo[id][bName]);                 fwrite(File, str);
        fclose(File);
    }
    fclose(File);
    return 1;
}
but it saves very good?
Reply
#6

Did you take a look at this method handling data in files? https://sampforum.blast.hk/showthread.php?tid=430722
Reply
#7

Quote:
Originally Posted by BigETI
Посмотреть сообщение
Did you take a look at this method handling data in files? https://sampforum.blast.hk/showthread.php?tid=430722
yeah that's very useful , thank you for that...
Reply
#8

I discovered that, OnFilterScriptInit doesn't load the function but why?
Reply
#9

bump.. sorry for that : D
Reply
#10

pawn Код:
if (strcmp("/loadmyhp", cmdtext, true) == 0)
    {
        new File:hp=fopen("/UsersHP.ini", io_read), string[200], str[200];
        fread(hp, str);
        format(string, 200, "The health you saved = %f", floatstr(str));
        SendClientMessage(playerid, -1, string);
        fclose(hp);
        return 1;
    }
Take a closer look people, where is the value of 'str' coming from? That's correct, nowhere... you haven't set a value for 'str' in your /loadmyhp command. So it is reading 0 by default, therefore it will load 0 as well.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)