INI_ParseFile
#1

Hey guys,

Im trying to load some data from a file in variables, but somehow im getting stuck using INI_ParseFile.
Somehow the things arent loading into the variables. They all just stay 0.000.
pawn Код:
stock LoadHouses()
{
    for( new i = 0; i <= MAX_HOUSES; i ++ )
    {
        printf( "I: %i", i );
        if( !fexist( hPath(i) ) ) break;
       
        INI_ParseFile(hPath(i), "LoadHouses_%i", .bExtra = true, .extra = i);
       
        printf( "HouseInfo[i][XPos] %0.4f || HouseInfo[i][YPos] %0.4f || HouseInfo[i][ZPos] %0.4f", HouseInfo[i][XPos], HouseInfo[i][YPos], HouseInfo[i][ZPos] );
        HouseEnter[i]  = CreateDynamicCP( HouseInfo[i][XPos], HouseInfo[i][YPos], HouseInfo[i][ZPos], 1.5, HouseInfo[i][VirtualWorld] );
        HouseExit[i] = CreateDynamicCP( 443.9237, 509.4609, 1001.4195, 1.5, HouseInfo[i][VirtualWorld] );
       
        new LabelString[128];
        switch( HouseInfo[i][Owned] )
        {
            case 0: format( LabelString, sizeof LabelString, "Dit huis is nog te koop! \nHuis ID: %i \nEigenaar: N/A \nPrijs: $%i", i, HouseInfo[i][Price] ), print( "Label 0" );
            case 1: format( LabelString, sizeof LabelString, "Huis ID: %i \nEigenaar: %s \nPrijs: $%i", i, HouseInfo[i][Owner], HouseInfo[i][Price] ), print( "Label 1" );
        }
       
        HouseInfo[i][HouseLabel] = Create3DTextLabel( LabelString, COLOR_GREEN, HouseInfo[i][XPos], HouseInfo[i][YPos], HouseInfo[i][ZPos], 25.0, HouseInfo[i][VirtualWorld] );
        HouseCount ++;
        printf( "Loaded house ID: %i", i );
    }
    return 1;
}
Im using that piece to load all the houses, and the public for the INI_ParseFile:
pawn Код:
forward LoadHouses_data(id, name[], value[]);
public LoadHouses_data(id, name[], value[])
{
    INI_Int( "Price", HouseInfo[id][Price] );
    printf( "Price: %i", HouseInfo[id][Price] );
   
    INI_Int( "Owned", HouseInfo[id][Owned] );
    printf( "Owned: %i", HouseInfo[id][Owned] );
   
    INI_Float( "Pickup_X", HouseInfo[id][XPos] );
    printf( "X: %f", HouseInfo[id][XPos] );
   
    INI_Float( "Pickup_Y", HouseInfo[id][YPos] );
    printf( "Y: %f", HouseInfo[id][YPos] );
   
    INI_Float( "Pickup_Z", HouseInfo[id][ZPos] );
    printf( "Z: %f", HouseInfo[id][ZPos] );
   
    INI_Int( "Virtualworld", HouseInfo[id][VirtualWorld] );
    printf( "VW: %i", HouseInfo[id][VirtualWorld] );
   
    INI_String( "Owner", HouseInfo[id][Owner], 24 );
    printf( "Owner: %s", HouseInfo[id][Owner] );
   
    INI_Bool( "Locked", HouseInfo[id][Locked] );
    printf( "Locked: %b", HouseInfo[id][Locked] );
    return 1;
}
And this is the output:
Код:
[09:24:42] I: 0
[09:24:42] HouseInfo[i][XPos] 0.0000 || HouseInfo[i][YPos] 0.0000 || HouseInfo[i][ZPos] 0.0000
[09:24:42] HouseCount: 0
[09:24:42] I: 1
[09:24:42] HouseInfo[i][XPos] 0.0000 || HouseInfo[i][YPos] 0.0000 || HouseInfo[i][ZPos] 0.0000
[09:24:42] HouseCount: 1
[09:24:42] I: 2
[09:24:42] HouseInfo[i][XPos] 0.0000 || HouseInfo[i][YPos] 0.0000 || HouseInfo[i][ZPos] 0.0000
[09:24:42] HouseCount: 2
[09:24:42] I: 3
[09:24:42] HouseInfo[i][XPos] 0.0000 || HouseInfo[i][YPos] 0.0000 || HouseInfo[i][ZPos] 0.0000
[09:24:42] HouseCount: 3
[09:24:42] I: 4
~Wesley
Reply
#2

Changed the '%i' to '%s', still no luck. All the variables are still at 0.000

Edit:
Hang on, if its the same thing as in format, then i should use %i though: im using 'i' as the extra, or am i wrong here?
Reply
#3

Ah okie, i thought it was for the .Extra
But anyways, that still didnt solved my problem. Do you know any other way what could cause this?
Reply
#4

Whenever i create the house, ill write in it immediately. Aswell as you buy/sell the house, it just changes the name etc.

pawn Код:
stock CreateHouse( playerid, price, owned, Float:x, Float:y, Float:z, virtualworld, ownername[])
{
    new id = HouseCount, INI:pFile = INI_Open(hPath(id)), Label[128];
    HouseInfo[id][Price] = price;
    HouseInfo[id][Owned] = owned;
    HouseInfo[id][XPos] = x;
    HouseInfo[id][YPos] = y;
    HouseInfo[id][ZPos] = z;
    HouseInfo[id][VirtualWorld] = virtualworld;
    strset( HouseInfo[id][Owner], ownername );
   
    HouseEnter[id]  = CreateDynamicCP( x, y, z, 1.5, GetPlayerVirtualWorld( playerid ) );
    HouseExit[id] = CreateDynamicCP( 443.9237, 509.4609, 1001.4195, 1.5, virtualworld );

    INI_WriteInt( pFile, "Prijs", price );
    INI_WriteInt( pFile, "Owned", 0 );
    INI_WriteInt( pFile, "Virtualworld", GetPlayerVirtualWorld( playerid ) );
    INI_WriteFloat( pFile, "Pickup_X", x );
    INI_WriteFloat( pFile, "Pickup_Y", y );
    INI_WriteFloat( pFile, "Pickup_Z", z );
    INI_WriteString( pFile, "Eigenaar", "HeeftGeenEigenaar" );
    INI_WriteBool( pFile, "Locked", true );
    INI_Close( pFile );
   
    switch( owned )
    {
        case 0: format( Label, sizeof Label, "Dit huis is nog te koop! \nHuis ID: %i \nEigenaar: N/A \nPrijs: $%i", id, price );
        case 1: format( Label, sizeof Label, "Huis ID: %i \nEigenaar: %s \nPrijs: $%i", id, ownername, price );
    }
   
    HouseInfo[id][HouseLabel] = Create3DTextLabel( Label, COLOR_GREEN, x, y, z, 25.0, GetPlayerVirtualWorld( playerid ) );
    HouseCount ++;
    return 1;
}
Example file after creation:
Код:
Prijs = 100
Owned = 0
Virtualworld = 0
Pickup_X = 2259.464599
Pickup_Y = -86.412368
Pickup_Z = 26.499542
Eigenaar = HeeftGeenEigenaar
Locked = true
Edit:
I actually noticed i didnt have INI_SetTag, added everywhere where it was needed, still not working
Reply
#5

Sorry for early bump, but ive found another 'bug'. When ever i create a house, it doesnt show a checkpoint. When i start the server on windows, it shows the checkpoint, but when im hosting it on a linux server it doesnt.
But back to the first problem, it still doenst load the files the right way, anyone who could help me?
Reply
#6

CreateHouse:
pawn Код:
stock CreateHouse( playerid, price, owned, Float:x, Float:y, Float:z, virtualworld, ownername[])
{
    new id = HouseCount, INI:pFile = INI_Open(hPath(id)), Label[128];
    HouseInfo[id][Price] = price;
    HouseInfo[id][Owned] = owned;
    HouseInfo[id][XPos] = x;
    HouseInfo[id][YPos] = y;
    HouseInfo[id][ZPos] = z;
    HouseInfo[id][VirtualWorld] = virtuwalworld;
    strset( HouseInfo[id][Owner], ownername );
   
    HouseEnter[id]  = CreateDynamicCP( x, y, z, 1.5, GetPlayerVirtualWorld( playerid ) );
    HouseExit[id] = CreateDynamicCP( 443.9237, 509.4609, 1001.4195, 1.5, virtualworld );

    INI_SetTag( pFile, "tag" );
    INI_WriteInt( pFile, "Prijs", price );
    INI_WriteInt( pFile, "Owned", 0 );
    INI_WriteInt( pFile, "Virtualworld", GetPlayerVirtualWorld( playerid ) );
    INI_WriteFloat( pFile, "Pickup_X", x );
    INI_WriteFloat( pFile, "Pickup_Y", y );
    INI_WriteFloat( pFile, "Pickup_Z", z );
    INI_WriteString( pFile, "Eigenaar", "HeeftGeenEigenaar" );
    INI_WriteBool( pFile, "Locked", true );
    INI_Close( pFile );
   
    switch( owned )
    {
        case 0: format( Label, sizeof Label, "Dit huis is nog te koop! \nHuis ID: %i \nEigenaar: N/A \nPrijs: $%i", id, price );
        case 1: format( Label, sizeof Label, "Huis ID: %i \nEigenaar: %s \nPrijs: $%i", id, ownername, price );
    }
   
    HouseInfo[id][HouseLabel] = Create3DTextLabel( Label, COLOR_GREEN, x, y, z, 25.0, GetPlayerVirtualWorld( playerid ) );
    HouseCount ++;
    return 1;
}
LoadHouse:
pawn Код:
stock LoadHouses()
{
    for( new i = 0; i <= MAX_HOUSES; i ++ )
    {
        printf( "I: %i", i );
        if( !fexist( hPath(i) ) ) break;
       
        INI_ParseFile(hPath(i), "LoadHouses_%s", .bExtra = true, .extra = i);
       
        printf( "HouseInfo[i][XPos] %0.4f || HouseInfo[i][YPos] %0.4f || HouseInfo[i][ZPos] %0.4f", HouseInfo[i][XPos], HouseInfo[i][YPos], HouseInfo[i][ZPos] );
        HouseEnter[i]  = CreateDynamicCP( HouseInfo[i][XPos], HouseInfo[i][YPos], HouseInfo[i][ZPos], 1.5, HouseInfo[i][VirtualWorld] );
        HouseExit[i] = CreateDynamicCP( 443.9237, 509.4609, 1001.4195, 1.5, HouseInfo[i][VirtualWorld] );
       
        new LabelString[128];
        switch( HouseInfo[i][Owned] )
        {
            case 0: format( LabelString, sizeof LabelString, "Dit huis is nog te koop! \nHuis ID: %i \nEigenaar: N/A \nPrijs: $%i", i, HouseInfo[i][Price] ), print( "Label 0" );
            case 1: format( LabelString, sizeof LabelString, "Huis ID: %i \nEigenaar: %s \nPrijs: $%i", i, HouseInfo[i][Owner], HouseInfo[i][Price] ), print( "Label 1" );
        }
       
        HouseInfo[i][HouseLabel] = Create3DTextLabel( LabelString, COLOR_GREEN, HouseInfo[i][XPos], HouseInfo[i][YPos], HouseInfo[i][ZPos], 25.0, HouseInfo[i][VirtualWorld] );
        HouseCount ++;
        printf( "Loaded house ID: %i", i );
    }
    return 1;
}
Reply
#7

Eehm...

pawn Код:
HouseInfo[id][VirtualWorld] = virtuwalworld;
...
Reply
#8

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
Eehm...

pawn Код:
HouseInfo[id][VirtualWorld] = virtuwalworld;
...
Must have been a typo when pasting it on the forum.. :$
Compiles just file without any errors
Reply
#9

Anyone can helpz me?
Reply
#10

Sorry for the bump but I pretty much have a similar problem. I'm reading a float from a house file (in my case it's a flat), save it into an enum and when I print the enum entry for the float it returns 0.000000:

http://pastebin.com/mGga24Q2
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)