Y_ini loop loading question
#1

This method works well for saving multi dimensional variables, however I have a problem loading them.

pawn Код:
new Float: gSomeVar[20][20][20];

Save(id)
{
    for(new a; a < 20; a++)
    {
        for(new c; c < 20; c++)
        {
            format(str,sizeof(str),"Test%d%d", a, b);
            INI_WriteFloat(File, str, gSomeVar[id][a][b]);
        }
    }
}
pawn Код:
// ..
TestPath(id)
{
    new str[20];
    format(str, sizeof(str), "/test/%d.ini", id);
    return str;
}

forward LoadTest_data(id, name[], value[]);
public LoadTest_data(id, name[], value[])
{
    new str[20];
    for(new a; a < 20; a++)
    {
        for(new b; b < 20; b++)
        {
            format(str, sizeof(str),"Test%d%d", a, b);
            INI_Float(str, gSomeVar[id][a][b]);
        }
    }
    return 1;
}

// ...
for(new a; a < 20; a++)
{
    INI_ParseFile(TestPath(a), "LoadTest_%s", .bExtra = true, .extra = a);
}
Reply
#2

pawn Код:
public LoadTest_data(id, name[], value[])
{
    new str[20];
    for(new a; a < 20; a++)
    {
        format(str, sizeof(str),"Test%d%d", id, a);
        INI_Float(str, gSomeVar[id][a]);
    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
public LoadTest_data(id, name[], value[])
{
    new str[20];
    for(new a; a < 20; a++)
    {
        format(str, sizeof(str),"Test%d%d", id, a);
        INI_Float(str, gSomeVar[id][a]);
    }
    return 1;
}
My bad :/, the variable is actually:
- Edited the main topic.
pawn Код:
new Float: gSomeVar[20][20][20];
Reply
#4

pawn Код:
format(str, sizeof(str),"Test%d%d%d", id, a, b);
Reply
#5

I don't understand why to save the id inside the string... That's not even working by the way.
You have the file variable which save the variables into the path, however you must enter an id to the loading function.
pawn Код:
Save(id)
{
    new INI:File = INI_Open(TestPath(id));
//                                    ^
    INI_SetTag(File, "Testdata");
    // ..
    return 1;
}
pawn Код:
public LoadTest_data(id, name[], value[])
//                    ^
{
    new str[20];
    for(new a; a < 20; a++)
    {
        for(new b; b < 20; b++)
        {
            format(str, sizeof(str),"Test%d%d", a, b);
            INI_Float(str, gSomeVar[id][a][b]);
            //                       ^
        }
    }
    return 1;
}
Reply
#6

Maybe y_ini doesnt supports three dimensional arrays, try

pawn Код:
public LoadTest_data(id, name[], value[])
{
    new str[20],Float:SomeArray;
    for(new a,b; a < 20; a++)
    {
        for(b=0; a < 20; a++)
        {
            format(str, sizeof(str),"Test%d%d", a, b);
            INI_Float(str, SomeArray);
            gSomeVar[id][a][b] = SomeArray;
        }
    }
    return 1;
}
Reply
#7

Well.. I must admit that it saves everything fine..
EDIT: looks like nothing is being loaded.. I also save string but for some weird reason it won't even load that..
(just apart of the code)
pawn Код:
new Float: gSomeVar[20][20][20];

TestPath(id)
{
    new str[20];
    format(str, sizeof(str), "/test/%d.ini", id);
    return str;
}

public OnGameModeInit()
{
     LoadAllTests();
     return 1;
}

Save(id)
{
    new str[20];
    for(new a; a < 20; a++)
    {
        for(new c; c < 20; c++)
        {
            format(str, sizeof(str),"Test%d%d", a, b);
            INI_WriteFloat(File, str, gSomeVar[id][a][b]);
        }
    }
    return 1;
}

LoadAllTests()
{
    for(new x = 1; x < 20; x++)
    {
        if(fexist(TestPath(x)))
        {
            INI_ParseFile(TestPath(x), "LoadTest_%s", .bExtra = true, .extra = x)
        }
    }
    return 1;
}

forward LoadTest_data(id, name[], value[]);
public LoadTest_data(id, name[], value[])
{
    new str[20];
    for(new a; a < 20; a++)
    {
        for(new b; b < 20; b++)
        {
            format(str, sizeof(str),"Test%d%d", a, b);
            INI_Float(str, gSomeVar[id][a][b]);
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)