Y_INI read from ini, set variable
#4

Quote:
Originally Posted by Nathan_Taylor
View Post
But what if one of the lines in the INI file is something like...
Faction = LSPD

or does everything have to be integers? like..
Faction_ID = 3

Or what is bool?
It can be however you like. Reading from a file is done with INI_ParseFile, like so..

Say you wanted to read from "scriptfiles/settings.ini"...

pawn Code:
INI_ParseFile( "settings.ini", "LoadSettings_%s" );
// "settings.ini" is our file, and "LoadSettings" is our callback.
pawn Code:
public LoadSettings_info ( name[], value[] )
{
    // Every time you write information to the settings file, you have to use INI_SetTag( fileVariable, "info" );

    INI_Int(            "OOC",              ooc );
    // This loads the integer "OOC" into the variable "ooc"

    INI_String(         "FACTION_0",          FactionNames [ 0 ], 64 );
    // This loads the string "Faction" into the variable "FactionNames [ 0 ]" with a length of 64 cells.
}
Writing to the settings file would be like this..

pawn Code:
new
    INI: mySettingFile = INI_Open( "settings.ini" );

INI_SetTag( mySettingFile, "info" );

INI_WriteInt( mySettingFile, "OOC", 1 );

INI_WriteString( mySettingFile, "FACTION_0", "LSPD" );

INI_Close( mySettingFile );
// Don't forget to close the file after you're done working with it!
I'm pretty sure Y_INI supports booleans as well but I have never really messed with them, so I'm not positive.
Reply


Messages In This Thread
[No subject] - by Nathan_Taylor - 28.02.2013, 19:44
Re: Y_INI read from ini, set variable - by LarzI - 28.02.2013, 22:23
Re: Y_INI read from ini, set variable - by Nathan_Taylor - 28.02.2013, 22:30
Re: Y_INI read from ini, set variable - by 2KY - 01.03.2013, 00:00
Re: Y_INI read from ini, set variable - by Nathan_Taylor - 01.03.2013, 00:32
Re: Y_INI read from ini, set variable - by 2KY - 01.03.2013, 00:33
Re: Y_INI read from ini, set variable - by Nathan_Taylor - 01.03.2013, 00:35
Re: Y_INI read from ini, set variable - by 2KY - 01.03.2013, 00:48
Re: Y_INI read from ini, set variable - by Nathan_Taylor - 01.03.2013, 01:08
Re: Y_INI read from ini, set variable - by 2KY - 01.03.2013, 01:09

Forum Jump:


Users browsing this thread: 2 Guest(s)