Raised This Month: $32 Target: $400
 8% 

KeyValue Questions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 03-29-2013 , 02:43   KeyValue Questions
Reply With Quote #1

So I have a question hopefully someone knows this for me.. Btw i am testing and have done some searches... Im lookging at various example and cant find anything on this so...

Code:
"Root"
{
     "SomeKey"
     {
          "Unknown Key"     "Value" //I need the key and value
     }
}
I know how to retrieve the section name. But is there anway to loop through and get the names of the keys?
Doc-Holiday is offline
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 03-29-2013 , 03:23   Re: KeyValue Questions
Reply With Quote #2

didn't try myself

PHP Code:
decl String:section[128], String:value[256];
    if (
KvGotoFirstSubKey(kvtrue))
    {
        do 
        {
            
KvSavePosition(kv);
            
            
KvGetSectionName(kvsectionsizeof(section));
            
PrintToServer("Started looping keys from %s section"section);
            
            if (
KvGotoFirstSubKey(kvfalse))
            {
                do
                {
                    
KvGetSectionName(kvsectionsizeof(section));
                    
KvGetString(kvNULL_STRINGvaluesizeof(value));
                    
PrintToServer("--> Key: %s | Value: %s"sectionvalue);
                }
                while (
KvGotoNextKey(kvfalse));
            }
            
            
KvGoBack(kv);
        }
        while (
KvGotoNextKey(kvtrue));
    }
    
KvRewind(kv); 
Despirator is offline
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 03-29-2013 , 03:33   Re: KeyValue Questions
Reply With Quote #3

tested and worked. Full code i've used

PHP Code:
public OnPluginStart()
{
    
RegConsoleCmd("sm_test"Command_Test);
}

public 
Action:Command_Test(clientargs)
{
    
decl String:buffer[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMbuffersizeof(buffer), "configs/test.txt");
    
    new 
Handle:kv CreateKeyValues("test");
    
    if (!
FileToKeyValues(kvbuffer))
    {
        
ReplyToCommand(client"Could not test file: %s"buffer);
        
CloseHandle(kv);
        return 
Plugin_Handled;
    }
    
ReplyToCommand(client"Testing file: %s"buffer);
    
    
decl String:section[128], String:value[256];
    if (
KvGotoFirstSubKey(kvtrue))
    {
        do 
        {
            
KvSavePosition(kv);
            
            
KvGetSectionName(kvsectionsizeof(section));
            
ReplyToCommand(client"Started looping keys from %s section"section);
            
            if (
KvGotoFirstSubKey(kvfalse))
            {
                do
                {
                    
KvGetSectionName(kvsectionsizeof(section));
                    
KvGetString(kvNULL_STRINGvaluesizeof(value));
                    
ReplyToCommand(client"--> Key: %s | Value: %s"sectionvalue);
                }
                while (
KvGotoNextKey(kvfalse));
            }
            
            
KvGoBack(kv);
        }
        while (
KvGotoNextKey(kvtrue));
    }
    
CloseHandle(kv);
    
    
ReplyToCommand(client"Finished testing file: %s"buffer);
    
    return 
Plugin_Handled;

test.txt structure


output

Last edited by Despirator; 03-29-2013 at 03:36.
Despirator is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-29-2013 , 03:55   Re: KeyValue Questions
Reply With Quote #4

textparse
output

SMC
__________________
Do not Private Message @me
Bacardi is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 03-29-2013 , 09:20   Re: KeyValue Questions
Reply With Quote #5

Very nice guys Thanks for the replies
Doc-Holiday is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:28.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode