View Single Post
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 01-24-2015 , 15:38   Re: [SOLVED] KeyValue Parsing
Reply With Quote #6

Quote:
Originally Posted by Potato Uno View Post
This is a huge pain in the ass to do, sometimes getting to the point where I just write something random and it works, and I write something that SHOULD work and it does absolutely nothing.

Relevant code:

PHP Code:
    do
    {
        
// Grab the ID
        
decl String:AttributeID[6];
        
KvGetSectionName(handleAttributeID6);
        
        
// Grab its value
        
decl String:AttributeValue[20];
        
KvGetString(handleAttributeIDAttributeValue20);
        
        
ServerCommand("say [%s, %s]"AttributeIDAttributeValue);
        
    } while (
KvGotoNextKey(kvfalse)); 
Relevant section of the file:

PHP Code:
        "Weapons"
        
{
            
"0"
            
{
                
"81"    "2.0"
                "25"    "3.0"
            
}
        } 
Server prints out:

PHP Code:
[81, ]
[
25, ] 
I want it to print out:

PHP Code:
[812.0]
[
253.0
Any reasons why it's not grabbing the decimal values from the file? Does the KV stack have to point at the "0" node before I use the "KvGetString" native, and do I have to have all the known keys (81, 25) prior to grabbing the decimal values? (Which would require 2 iterations on the section - 1 to grab the keys and then 1 to grab the values - and that sounds like a performance sink.)

You may NOT assume that I know what the keys & values of the "0" block is. (That is, the keys can vary to be 22, 28, 45 or 1, 2, 3, 4 or any size + combo of numbers.)

Thanks!

============================================= ==

Problem has been solved. The bolded section of that question I asked is the answer to the problem (have to get the keys once, then go back up a node, then get the values). This is, of course, assuming the keys inside the section are not known. (If the keys are known, then just directly get the values.)
this should work:
PHP Code:
    do
    {
        
// Grab the ID
        
decl String:AttributeID[6];
        
KvGetSectionName(handleAttributeID6);
        
        
// Grab its value
        
decl String:AttributeValue[20];
        
KvGetString(handleNULL_STRINGAttributeValue20); //Docs say: Name of the key, or NULL_STRING.
        
        
ServerCommand("say [%s, %s]"AttributeIDAttributeValue);
        
    } while (
KvGotoNextKey(kvfalse)); 
__________________

Last edited by WildCard65; 01-24-2015 at 15:39.
WildCard65 is offline