[YINI] Read to variable
#1

Hello guys, i create one code to create new file or read from this:

Код:
public DPLS()
{
	if(fexist("DMRPG/Buildings/DPLS.ini"))
	{
	    new INI:ini = INI_Open("DMRPG/Buildings/DPLS.ini");
            INI_Int("Dinheiro",DPLS_cash);
            INI_Int("Materiais",DPLS_materiais);
	    INI_Close(ini);
	}
	else // se nгo existe irб criar o arquivo
	{
 		new INI:ini = INI_Open("DMRPG/Buildings/DPLS.ini");
	        INI_SetTag(ini, "DPLS VARs");
		INI_WriteInt(ini, "Dinheiro", 1001);
		INI_WriteInt(ini, "Materiais", 1002);
		INI_Close(ini);
	}
	return 1;
}
In the top of GameMode i have 2 variables:
Код:
new DPLS_cash;
new DPLS_materiais;
I want to load the values of "Dinheiro" and "Materiais" into "DPLS_cash" and "DPLS_materiais" respectively.

For now i have these errors:
Код:
\SAMP - SERVER\samp037_svr_R2-1-1_win32\gamemodes\HA-GM.pwn(580) : error 017: undefined symbol "name"
\SAMP - SERVER\samp037_svr_R2-1-1_win32\gamemodes\HA-GM.pwn(580) : error 017: undefined symbol "value"
\SAMP - SERVER\samp037_svr_R2-1-1_win32\gamemodes\HA-GM.pwn(581) : error 017: undefined symbol "name"
\SAMP - SERVER\samp037_svr_R2-1-1_win32\gamemodes\HA-GM.pwn(581) : error 017: undefined symbol "value"
Line 580 and 581 is the RED painted
Reply
#2

Quote:
Originally Posted by Hayden_Almeida
Посмотреть сообщение
Hello guys, i create one code to create new file or read from this:

Код:
public DPLS()
{
	if(fexist("DMRPG/Buildings/DPLS.ini"))
	{
	    new INI:ini = INI_Open("DMRPG/Buildings/DPLS.ini");
            INI_Int("Dinheiro",DPLS_cash);
            INI_Int("Materiais",DPLS_materiais);
	    INI_Close(ini);
	}
	else // se nгo existe irб criar o arquivo
	{
 		new INI:ini = INI_Open("DMRPG/Buildings/DPLS.ini");
	        INI_SetTag(ini, "DPLS VARs");
		INI_WriteInt(ini, "Dinheiro", 1001);
		INI_WriteInt(ini, "Materiais", 1002);
		INI_Close(ini);
	}
	return 1;
}
In the top of GameMode i have 2 variables:
Код:
new DPLS_cash;
new DPLS_materiais;
I want to load the values of "Dinheiro" and "Materiais" into "DPLS_cash" and "DPLS_materiais" respectively.

For now i have these errors:
Код:
\SAMP - SERVER\samp037_svr_R2-1-1_win32\gamemodes\HA-GM.pwn(580) : error 017: undefined symbol "name"
\SAMP - SERVER\samp037_svr_R2-1-1_win32\gamemodes\HA-GM.pwn(580) : error 017: undefined symbol "value"
\SAMP - SERVER\samp037_svr_R2-1-1_win32\gamemodes\HA-GM.pwn(581) : error 017: undefined symbol "name"
\SAMP - SERVER\samp037_svr_R2-1-1_win32\gamemodes\HA-GM.pwn(581) : error 017: undefined symbol "value"
Line 580 and 581 is the RED painted
You are opening a handle to write data in YINI, you can't use INI_Int.

I think you meant to do this:

You could use INI_ParseFile or INI_Load to retrieve information.
Reply
#3

SOLVED:
on top of game Mode i create the variables i want to store (global vars):
Код:
new DPLS_cash;
new DPLS_materiais;
Here we look if exists or not, if not then create the file:
OnGameModeInit: (on server start, it will run)
Код:
	if(fexist("DMRPG/Buildings/DPLS.ini"))
	{
	    if(togPainel == 1) { print("Arq. DPLS - Existe"); } // You can Delete this line
            INI_ParseFile("DMRPG/Buildings/DPLS.ini", "DPLS");
	}
	else // se nгo existe irб criar o arquivo
	{
	    if(togPainel == 1) { print("Arq. DPLS - Nao Existe"); } // You can Delete this line
 		new INI:ini = INI_Open("DMRPG/Buildings/DPLS.ini");
	        INI_SetTag(ini, "DPLS VARs");
		INI_WriteInt(ini, "Dinheiro", 1001);
		INI_WriteInt(ini, "Materiais", 1002);
		INI_Close(ini);
		INI_ParseFile("DMRPG/Buildings/DPLS.ini", "DPLS");
	}
I create forwards on top of GM:
Код:
forward DPLS(name[], value[]);
forward Save_DPLS();
now the Publics:
Код:
public DPLS(name[], value[]) //here we are Reading
{
    if(togPainel == 1) { print("Public DPLS - Leitura"); } // You can Delete this line
	INI_Int("Dinheiro",DPLS_cash);
    INI_Int("Materiais",DPLS_materiais);
    return 0;
}
public Save_DPLS() //Here we are Saving
{
    if(togPainel == 1) { print("Public Save_DPLS"); } // You can Delete this line
 	new INI:File = INI_Open("DMRPG/Buildings/DPLS.ini");
    INI_SetTag(File,"DPLS VARs");
    INI_WriteInt(File,"Dinheiro",DPLS_cash);
    INI_WriteInt(File,"Materiais",DPLS_materiais);
    INI_Close(File);
	return 1;
}
And Finally, to save the file from the vars:
Код:
public OnGameModeExit()
{
	Save_DPLS();
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)