How to make Y_INI loop through all variables, without knowing the name of the variables?
#1

I've made a phone contacts system which basically saves player's number under a chosen name.
However, I can't think of a way of loading the values without knowing the name of the variables, I can do it when a single number is requested, but I'm trying to make a command which would list ALL of the saved numbers along with the given name.

The .ini save files containing phone contacts are named by the player's phone number, so if player x's phone number was 65, it'd be 65.ini, and inside of that his phone contacts would be saved.

However, contacts are saved in a format like this:
Код:
NUMBER = CONTACTNAME
For example, this is 714967894.ini:
Код:
[data]
726268636 = Jerry
How would I load ALL the variables stored inside without really knowing the name of the variables inside and how many there are?
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
y_ini passes keys and values to the ParseFile callback, so just read the "name" variable.
So, I could just do
pawn Код:
printf("Name: %i | Value: %s", name, value);
And it'll print everything inside the file out?
Reply
#3

That answers my question, thank you very much. +REP
Reply
#4

I have a question, what does Y_INI return if there's no such variable found in the .ini?
pawn Код:
forward LoadContactName_data(phonenumber, name[], value[]);
public LoadContactName_data(phonenumber, name[], value[])
{
    new string[128];
    valstr(string, phonenumber);
    INI_String(string, LoadPhoneNumber, 64);
    return 1;
}
For example, if it does not find the variable string in the .ini, what value would LoadPhoneNumber get?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)