KeyValues

From Valve Developer Community
Revision as of 20:59, 10 January 2006 by Ts2do (talk | contribs)
Jump to navigation Jump to search

KeyValeus handles input and output.

The KeyValues class can load the input from a data buffer or a file.

The format of a data buffer or file is the following.

"SuperKey1"	"Value"
"SuperKey2"
{
	"Key1"	"Value"
	"Key2"
	{
		"SubKey1"	"Value"
		"SubKey2"
		{
			And so on...
		}
	}
}

Useful Traverses

The following loops are contained in the following function: void Traverse(KeyValues *pKV);

for ( KeyValues *sub = pKV->GetFirstSubKey(); sub; sub = sub->GetNextKey() )
This loop steps through all subkeys contained in pKV.
To handle subkeys with their own subkeys in pKV, you may want use a recursive loop. To check if a subkey has subkeys, do the following:
if(sub->GetFirstSubKey())
{
	Traverse(sub);
}
for ( KeyValues *sub = pKV->GetFirstValue(); sub; sub = sub->GetNextValue() )
This loop steps through all subkeys contained in a pKV that have values.
It is also valid to use the KeyValues member function GetDataType in the loop to do a type specific traverse.