Y_INI Dynamics
#1

Hello, I created a dynamic function in which it works something like this:

FIRST:
If the settings file doesn't exist, it will create it in the scriptfiles folder. Here is what it will write in it:

Code:
[Slots]
Created Slots = 0
Then, when someone writes a command like "/createslot TESTSLOT1", it will write in that file into something like this:

Code:
[Slots]
Created Slots = 1
[1]
SlotName1 = TESTSLOT1
Then when someone writes that command some more like "/createslot TESTSLOT2", it will write in that file into something like this:

Code:
[Slots]
Created Slots = 2
[1]
SlotName1 = TESTSLOT1
[2]
SlotName2 = TESTSLOT2
and so on... The reason why I made it like this:

Code:
[Slots]
Created Slots = [CREATE SLOTS]
[NUMBER]
SlotName[NUMBER] = TESTSLOT1
[NUMBER]
SlotName[NUMBER] = TESTSLOT2
is for me to create some sort of loop which will check if that SlotName[Number] is empty (I made a function like /deleteslot [NUMBER] and it will delete the SlotName[Number] in the file for example /deleteslot 2 will become:

Code:
[Slots]
Created Slots = 2
[1]
SlotName1 = TESTSLOT1
[2]
SlotName2 =
and I can create some sort of loop which is functioning like this:

pawn Code:
//global:
new slotname[128];
new FoundTheLine[128];

stock LoopThroughAllSlotLines()
{
    for(new i = 1; i < TOTAL_CREATED_SLOTS && EndTheLoop == 0; i++)
    {
        format(slotname,sizeof(slotname),"SlotName%d",i);
        INI_ParseFile(ConfigFile, "CheckTheLine", .bExtra = true, .extra = i);
         }

//found it:
 printf("% is empty!",FoundTheLine);

return 1;
}
CheckTheLine:

pawn Code:
forward CheckTheLine(i, name[], value[]);
public CheckTheLine(i, name[], value[])
{

    INI_String(slotname,TheGroupName,256);
    if (strlen(TheGroupName) == 0)
    {
    FoundEmptyLine = TheGroupName;
    EndTheLoop = 1;
    }
    return 1;
}
Long story short, I don't know how to read each line and find if the line is empty so I created this whole thing, if you understand this topic, tell me if there is a way to do this instead of using this whole thing system that I made. Trust me, you do not want me to tell the complexity of the problem.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)