Raised This Month: $51 Target: $400
 12% 

Is it possible to get the keyvalue key name and value by index?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LinLinLin
Senior Member
Join Date: Sep 2021
Old 08-19-2023 , 19:59   Is it possible to get the keyvalue key name and value by index?
Reply With Quote #1

I want to get the first key and value at some sections, but i don't know his keyname so kv.GetString seems not work. Is there another way to get both of them use someting like index?
LinLinLin is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 08-20-2023 , 23:03   Re: Is it possible to get the keyvalue key name and value by index?
Reply With Quote #2

something like this:
PHP Code:
if(KvGotoFirstSubKey(kvfalse)) do
{
    
KvGetSectionName(kvkeysizeof(key));
    
KvGetString(kvNULL_STRINGvaluesizeof(value));
} while(
KvGotoNextKey(kvfalse)); 
__________________
Grey83 is offline
LinLinLin
Senior Member
Join Date: Sep 2021
Old 08-21-2023 , 12:35   Re: Is it possible to get the keyvalue key name and value by index?
Reply With Quote #3

Quote:
Originally Posted by Grey83 View Post
something like this:
PHP Code:
if(KvGotoFirstSubKey(kvfalse)) do
{
    
KvGetSectionName(kvkeysizeof(key));
    
KvGetString(kvNULL_STRINGvaluesizeof(value));
} while(
KvGotoNextKey(kvfalse)); 
no, your can't go to the first subkey actually when only have key - value in one section.
I test a kv like that and in section A if you want to use GoToFirstSubkey, it return false. Only can get the value in section A by using a known key and use GetString(key, ...).
Code:
"root"
{
    "A"
    {
         "key"  "value"
         "key"  "value"
         "key"  "value"
         "key"  "value"
    }
}
I solve my problem in a not perfect way.
Since the key is custom, i have to store it like:
Code:
"root"
{
    "A"
    {
         "key"
          {
             "key"  "value"
          }
         "key"
          {
             "key"  "value"
          }
         "key"
          {
             "key"  "value"
          }
         "key"
          {
             "key"  "value"
          }
         "key"
          {
             "key"  "value"
          }
    }
}
LinLinLin is offline
Skyy
AlliedModders Donor
Join Date: Jan 2010
Location: Toronto, Canada
Old 08-22-2023 , 09:33   Re: Is it possible to get the keyvalue key name and value by index?
Reply With Quote #4

If you create your own custom sort, you will know exactly which position said key is always in, and can immediately call it without cycling through all the keys and sub keys. This is great for two reasons: quick lookups and guarantees a linear time complexity.

Last edited by Skyy; 08-22-2023 at 09:34.
Skyy is offline
Reply



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 21:28.


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