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

Keyvalues


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Stormsys
Member
Join Date: Oct 2005
Old 10-02-2006 , 15:08   Keyvalues
Reply With Quote #1

Quote:
"payers"
{
"SteamID:0:00000000"
{
"lol" "1"
}
}
Now my question is how do i create the subkey and how do i then retrive it after i used ->deleatethis

thanks,
Storm™
Stormsys is offline
L. Duke
Veteran Member
Join Date: Apr 2005
Location: Walla Walla
Old 10-02-2006 , 16:25   Re: Keyvalues
Reply With Quote #2

First, you can't retrieve/use a key value after you delete it. You delete it when you are done.

Second, if you have a file gaben.txt
Code:
"gaben"
{
    "firstkey"
    {
        "food" "donuts"
    }

    "secondkey"
    {
        "food" "fried chicken"
    }
}
and you want food is associated with the firstkey, this will print it:
Code:
CON_COMMAND(kv_test, "test keyvalues")
{
    // open KeyValues file
    KeyValues *MainKV = new KeyValues("gaben");
    bool found = MainKV->LoadFromFile(gFileSystem, "addons/myplugin/gaben.txt");
    if (!found)
    {
        MainKV->deleteThis();
        META_CONPRINTF("error opening MainKV\n");
        return;
    }

    // find sub key
    KeyValues *SubKV = MainKV->FindKey("firstkey");
    if (SubKV)
    {
        META_CONPRINTF("food for firstkey is '%s'\n", SubKV->GetString("food"));
        SubKV->deleteThis();
    }
    else
    {
        META_CONPRINTF("could not find SubKV\n");
    }
    
    MainKV->deleteThis();
}
Console should look like this when you type 'kv_test':
Code:
kv_test
food for firstkey is 'donuts'
No file will say "error opening MainKV" and if "firstkey" is not found it will say "could not find SubKV".
L. Duke is offline
Stormsys
Member
Join Date: Oct 2005
Old 10-02-2006 , 16:37   Re: Keyvalues
Reply With Quote #3

yep duke i understood that in our chat, but what happens if it dosent exist how is it created
Stormsys is offline
L. Duke
Veteran Member
Join Date: Apr 2005
Location: Walla Walla
Old 10-02-2006 , 17:14   Re: Keyvalues
Reply With Quote #4

Never tried it, but I assume you would do
Code:
KeyValues *pMyNewSubKey = new KeyValues("mysubkey");
pMyNewSubKey->SetString("food", "mmmm...beer");
MainKV->AddSubKey(pMyNewSubKey);
I would suggest searching the SDK code to see how Valve does it. It looks like they use AddSubKey in cl_smoke_trail.cpp, FileOpenDialog.cpp, InputDialog.cpp, ListPanel.cpp, etc.

Last edited by L. Duke; 10-02-2006 at 17:19.
L. Duke 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 07:12.


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