[YINI] Read to variable
#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


Messages In This Thread
[YINI] Read to variable - SOLVED - by Hayden_Almeida - 06.11.2015, 22:51
Re: [YINI] Read to variable - by ThePhenix - 06.11.2015, 23:48
Re: [YINI] Read to variable - by Hayden_Almeida - 07.11.2015, 00:12

Forum Jump:


Users browsing this thread: 1 Guest(s)