Keyvalues

From EventScripts Community Encyclopedia


Module: keyvalues

Module Overview

EventScripts version: 2.0

Table of Contents

Contents


Description

This module provides access to the KeyValues object which is used to provide full recursive access to Valve's KeyValues C++ class and file format.

Quick Example

import keyvalues
 
def toying():
    # assumes keygroup "mystuff" exists ( es.keygroupcreate("mystuff") )
    mystuff = keyvalues.getKeyGroup("mystuff")
 
   
    # similar to es.keycreate("mystuff", "mykey")
    mystuff["mykey"] = keyvalues.KeyValues(name="mykey")
 
    # similar to es.keysetvalue("mystuff", "mykey", "myval", 33)
    mystuff["mykey"]["myval"] = 33
 
    # similar to es.keygetvalue("myvar", "mystuff", "mykey", "myval")
    myvar = mystuff["mykey"]["myval"]
 
    # similar to 
    #es_foreachkey k in mystuff "es_dbgmsg 0 server_var(k)"
    for k in mystuff:
        es.dbgmsg(0, k.getName())
 
    # not unlike es.keygroupsave("example_save")
    ok = keyvalues.getKeyGroup("example_save")
    ok.save("/es_example_save_db.txt")
 
    #similar to a
    #recursive es_foreachkey into subtrees
def printTree(k, depth=0):
    print " "*depth, "Name:", k.getName(), "val:", k.getString()
    for j in k:
        printTree(j, depth+1)

Module Content

Classes

keyvalues.KeyValues

Methods

keyvalues.getKeyGroup(name)

Obtains a KeyValues class that is a wrapper around an existing keygroup created by es.keygroupcreate or es_keygroupcreate. May crash the server if the KeyValues instance is referenced after the keygroup is removed.

See Also

blog comments powered by Disqus