How to read from Y_INI files?
#1

Hello. I'm learning to use Y_INI as it is aways faster than dini, and with some tutorial, i succeded to start my vehicle system. It creates the file, everything is good. Just, how can i read the file so i load the information?

Here's how it would be if i were using dini, but i want it Y_INI...

pawn Код:
forward LoadVehicleIDInfo();
public LoadVehicleIDInfo()
{
    new file[64];
    format(file, sizeof(file), "ids.ini");
    if(fexist(file))
    {
         VehicleIDInfo[CID] = dini_Int(file, "CARID");
    }
}
I tried this for Y_INI, but it gets me some errors....

pawn Код:
forward LoadVehicleIDInfo();
public LoadVehicleIDInfo()
{
    new
    carfile[] = "ids.ini",
    INI:iniFile = INI_Open(carfile);
    INI_Int("CARID", CarIDInfo[CID]);
    INI_Close(iniFile);
    return 1;
}
Код:
C:\Users\Ricardo\Desktop\Desktop\RRP New Version Windows\gamemodes\RRP.pwn(758) : error 017: undefined symbol "name"
C:\Users\Ricardo\Desktop\Desktop\RRP New Version Windows\gamemodes\RRP.pwn(758) : error 017: undefined symbol "value"
The error line is:

pawn Код:
INI_Int("CARID", CarIDInfo[CID]);
Thanks in advance.
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
Did you read both my tutorial and topic?
Yes... That's what embarasses me. xD I've been making tries for around 1 hour. I success to create files, but not to read from them.
Reply
#3

I readed it, but something is still failing..
Now i made a cmd to set CarIDInfo[CID] to 2, a cmd to check that value, and a cmd to parse the file and supposely load it, so as the file is set to 0, it should set CarIDInfo[CID] to 0, but it just don't..

I have this now..
pawn Код:
main()
{
    print("\n----------------------------------");
    print("Ricardo's Role-Play by Ricardo Rodrigues");
    print("----------------------------------\n");
    new
        id[] = "RRP/Vehicles/ids.ini";
    INI_Load(id);
}

CMD:carid2(playerid, params[])
{
    CarIDInfo[CID] = 2;
    return 1;
}
CMD:checkini(playerid, params[])
{
    new string[64];
    format(string, sizeof(string), "It is: %d", CarIDInfo[CID]);
    SendClientMessage(playerid, c_green, string);
    return 1;
}
CMD:setini(playerid, params[])
{
    INI_ParseFile("id.INI", "ini_%s_%s");
    return 1;
}

INI:id[ids](name[], value[])
{
    INI_Int("CARID", CarIDInfo[CID]);
    return 1;
}
The file has this in it..

Код:
[ids]
CARID=0
Reply
#4

It is still not working.. Now i did it this way:

pawn Код:
//This is almost on the top, before OnGameModeInit..
main()
{
    print("\n----------------------------------");
    print("Ricardo's Role-Play by Ricardo Rodrigues");
    print("----------------------------------\n");
    new
        ids[] = "RRP/Vehicles/ids.INI";
    INI_Load(ids);
}
CMD:carid2(playerid, params[])
{
    CarIDInfo[CID] = 2);
    return 1;
}
CMD:checkini(playerid, params[])
{
    new string[64];
    format(string, sizeof(string), "It is: %d", CarIDInfo[CID]);
    SendClientMessage(playerid, c_green, string);
    return 1;
}
CMD:setini(playerid, params[])
{
    INI_ParseFile("ids.INI", "ini_%s_%s");
    return 1;
}

//This is randomly in the script
INI:ids[ids](name[], value[])
{
    INI_Int("CARID", CarIDInfo[CID]);
    return 1;
}
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
How is "CID" defined and what is "setini" doing?
Well, i use that system of increasing 1 number in a file, so when i create a vehicle, it will up 1 ID. I am trying to load this file.

Like, when i create a vehicle in-game, CarIDInfo[CID] will up 1 number. To get this value, i wanted to load it from the file, so it wont bug if server crashes or something.

So my idea is to load ids.ini which saves the CID variable as CARID="TheID", set CarIDInfo[CID] to that value, so than when i create the vehicle file, it will be CarIDInfo[CID]+1, creating a file named 1 number up than the one before.


I made /setini to "suposly" load the file for the tests, til i get it to work, just so i don't have to edit the vehicle creating cmd all the time..

So now, there is a file named ids.ini, with CARID=0 inside.
When i create a car, it will set CarIDInfo[CID]++.
I than use /checkini(Just a random cmd name.. Nothing to do with its purposes) that will tell me what CarIDInfo[CID] is set to.
Than i have /setini, that suposely load the file, making CarIDInfo[CID] 0, as in the file it's writen 0, but it still same value.

Basicaly, it's just to understand how to load info from the file, so i can continue with my systems...


All i need to know is how to set CarIDInfo[CID] to the value wrote in ids.ini file.
Reply
#6

48+ hours passed. Bump.

I simply need to understand how to load ids.ini into the variable CarIDInfo[CID].
Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)