SA-MP Forums Archive
[PROBLEM] INI:File - 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: [PROBLEM] INI:File (/showthread.php?tid=600284)



[PROBLEM] INI:File - Dusan01 - 06.02.2016

Hi guys, i have a strange problem with saving files, im using y_ini and here is my example:

Код:
FUNCTION: SacuvajMarihuanu(idsadnice)
{
	new dFile[128];
	format(dFile, sizeof(dFile),"sadnice/Sadnica_%d.ini",idsadnice);
	new INI:File = INI_Open(dFile);
	INI_WriteInt(File,"Vrijeme",MI[idsadnice][sTime]);
	INI_WriteFloat(File,"X",MI[idsadnice][sX]);
	INI_WriteFloat(File,"Y",MI[idsadnice][sY]);
	INI_WriteFloat(File,"Z",MI[idsadnice][sZ]);
	INI_WriteFloat(File,"lpX",MI[idsadnice][slpX]);
	INI_WriteFloat(File,"lpY",MI[idsadnice][slpY]);
	INI_WriteFloat(File,"lpZ",MI[idsadnice][slpZ]);
        INI_Close(File);
	return 1;
}
The problem is on all this functions where i have opening and closing ini files, for some reason INI:File starts to be -1, and when i need to close that File i get
Код:
Accessing element at negative index -1
here is FUNCTION defined:
Код:
#define FUNCTION:%0(%1) \
		forward%0(%1); \
		public%0(%1)
EDIT #1:
If file does not exist it will not bug...


Re: [PROBLEM] INI:File - Mencent - 06.02.2016

When INI:File returns -1 then was no file found. Check if you have the file (Sadnica_%d.ini) in the folder sadnice.


Re: [PROBLEM] INI:File - Dusan01 - 06.02.2016

Quote:
Originally Posted by Mencent
Посмотреть сообщение
When INI:File returns -1 then was no file found. Check if you have the file (Sadnica_%d.ini) in the folder sadnice.
Okay, i will now add fexist check, and will post results later...


Re: [PROBLEM] INI:File - Dusan01 - 06.02.2016

Okay, if file does not exist, INI:File will not return -1, i added this for test, and created over 500 files, works perfect:
Код:
FUNCTION: SacuvajTest(idjelke)
{
    new dFile[128];
    new Float:test = 25.2;
	format(dFile, sizeof(dFile),"testfolder/Test_%d.ini",idjelke);
	new INI:File = INI_Open(dFile);
	INI_WriteFloat(File,"Test1",test);
	INI_WriteFloat(File,"Test2",test);
	INI_WriteFloat(File,"Test3",test);
	INI_WriteFloat(File,"Test4",test);
	INI_WriteFloat(File,"Test5",test);
	INI_WriteFloat(File,"Test6",test);
    INI_Close(File);
	return true;
}

CMD:maketest(playerid, params[]) {
        idtesta ++;
        SacuvajTest(idtesta);
        new dFile[128];
        format(dFile, sizeof(dFile),"testfolder/Test_%d.ini",idtesta);
        if(!fexist(dFile)) return VuzimirPoruka(dFile);
	return 1;
}