SA-MP Forums Archive
Y_ini loop saving question - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Y_ini loop saving question (/showthread.php?tid=478097)



Y_ini loop saving question - Loot - 27.11.2013

I was wondering, how to save multi dimensional variables with y_ini via a loop without repeating the same action (or using dini!!!).

pawn Код:
new Float: gSomeVar[25][3][3];

// ...
new INI:File = INI_Open("nice.ini");
INI_SetTag(File, "Test");

for(new v; v < 25; v++)
{
    for(new i; i < 3; i++)
    {
        INI_WriteFloat(File, "Test", gSomeVar[5][v][i]);
        // OR
        INI_WriteFloat(File, "Test%d%d", gSomeVar[5][v][i]);
        // OR - etc
        INI_WriteFloat(File, "Test%d\n", gSomeVar[5][v][i]);
    }
}
// ...
So the outcome will be something like:
pawn Код:
[Test]
Test00 = 99.9
Test01 = 99.9
Test02 = 99.9
Test10 = 99.9
Test11 = 99.9
Test12 = 99.9
Test20 = 99.9
Unlike the 'lazy' way:
pawn Код:
INI_WriteFloat(File, "Test1", gSomeVar[5][0][0]);
INI_WriteFloat(File, "Test2", gSomeVar[5][0][1]);
INI_WriteFloat(File, "Test3", gSomeVar[5][0][2]);
INI_WriteFloat(File, "Test4", gSomeVar[5][1][0]);
INI_WriteFloat(File, "Test5", gSomeVar[5][1][1]);
INI_WriteFloat(File, "Test6", gSomeVar[5][1][2]);
INI_WriteFloat(File, "Test7", gSomeVar[5][6][0]);
// ... etc



Re: Y_ini loop saving question - erminpr0 - 27.11.2013

Ok, I was wondering on how to do that to, I thought if I can do something like this..
99.9% I'm wrong, but that's my only solution xd
Код:
for(new var = 1; var < 8; ++var)
{
   new string[16];
   format(string, 16, "Test%d", var);
   INI_WriteFloat(someFile, string, gSomeVar[5][6][var]);
}



Re: Y_ini loop saving question - Jefff - 27.11.2013

pawn Код:
for(new a,b,c; a < 25; a++)
{
    for(b = 0; b < 3; b++)
    {
        for(c = 0; c < 3; c++)
        {
            format(str,sizeof(str),"Test%d%d",b,c);
            INI_WriteFloat(File, str, gSomeVar[a][b][c]);
        }
    }
}



Re: Y_ini loop saving question - Loot - 27.11.2013

Thank you Jefff!