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".