INI_ParseFile (Y_INI)
#1

I've currently got this inside of a timer:

pawn Код:
INI_ParseFile( "Source/Configure.me", "LoadConfig" );
Along with "LoadConfig" (outside of the timer of course)

pawn Код:
forward LoadConfig_data ( name[], value[] );
public LoadConfig_data ( name[], value[] )
{
    INI_Int(            "VOTEKICK",         Configuration [ Setting_VoteKick ] );
    INI_Int(            "FRIENDLYFIRE",     Configuration [ Setting_FriendlyFire ] );
   
    switch( Configuration [ Setting_VoteKick ] )
    {
        case 0: print ( "\t\tVoteKick: Disabled" );
        case 1: print ( "\t\tVoteKick: Enabled for everybody" );
        case 2: print ( "\t\tVoteKick: Enabled only for VIP" );
        case 3: print ( "\t\tVoteKick: Enabled only for Admins" );
    }
   
    switch( Configuration [ Setting_FriendlyFire ] )
    {
        case 0: print ( "\t\tFriendly Fire: Disabled" );
        case 1: print ( "\t\tFriendly Fire: Enabled" );
    }
    return true;
}
By the prints I can tell "LoadConfig" isn't being called - what's wrong with my ParseFile?
Reply
#2

Try:
pawn Код:
INI_ParseFile( "Source/Configure.me", "LoadConfig_%s" );
Reply
#3

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
Try:
pawn Код:
INI_ParseFile( "Source/Configure.me", "LoadConfig_%s" );
Just tried that messing around with it, and it doesn't work. Logically that wouldn't even make sense as it would be trying to load an empty string.
Reply
#4

Well seeing as your function is LoadConfig_data, where is it going to get the 'data' from? So by having %s, it will load LoadConfig_?, where ? can be anything and it will still load all associated files. It's not so much something to do with formatting strings, but telling the script to load anything that begins with 'LoadConfig'.

https://sampforum.blast.hk/showthread.php?pid=1138420#pid1138420
Reply
#5

Anyhow, doesn't work. I've attempted.
Reply
#6

Benzo is correct about the formatting - if you're reading from a tag "data", you would have to add _%s to the format, else it wouldn't load at all.

Second of all, when reading files with ParseFile, the local callback (LoadConfig_data in this case) will run until it finds the first value from the file, saves it, then runs again, and again until the last line of the file is found, then it stops. What this means is that whatever you do, as long as you don't read something after the prints, you'll never actually see the prints. Try putting a print between each and every line in the callback, and you'll see for yourself.

Here's how I would do it:
pawn Код:
INI_ParseFile( "Source/Configure.me", "LoadConfig_%s" );
switch( Configuration [ Setting_VoteKick ] )
{
    case 0: print ( "\t\tVoteKick: Disabled" );
    case 1: print ( "\t\tVoteKick: Enabled for everybody" );
    case 2: print ( "\t\tVoteKick: Enabled only for VIP" );
    case 3: print ( "\t\tVoteKick: Enabled only for Admins" );
}
 
switch( Configuration [ Setting_FriendlyFire ] )
{
    case 0: print ( "\t\tFriendly Fire: Disabled" );
    case 1: print ( "\t\tFriendly Fire: Enabled" );
}
pawn Код:
forward LoadConfig_data ( name[], value[] );
public LoadConfig_data ( name[], value[] )
{
    INI_Int(            "VOTEKICK",         Configuration [ Setting_VoteKick ] );
    INI_Int(            "FRIENDLYFIRE",     Configuration [ Setting_FriendlyFire ] );
   
    return true;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)