GithubHelp home page GithubHelp logo

vscript_keyvalues's Introduction

VScript KeyValues

Barebones standalone library that allows writing of Valve's KeyValues format.

Useful for writing out formatted files such as vmf, cfg, vdf, txt...

Usage

Include the keyvalues.nut script, i.e. IncludeScript("keyvalues").

Initialize a KeyValues class with a name, e.g. local kv = KeyValues("my_keyvalues.txt");

Key/value pairs can be added or modified using the generic Set function, or the type-specific Set<type> functions that perform conversions where available, e.g. SetFloat.

The FindKey function can be used to find an existing key, returning null if it does not exist.

Sub-keyvalues can be added by creating a new KeyValues class, then specifying the parent keyvalue as the 2nd argument in the constructor. Alternatively, AddSubKey can be called on the parent keyvalue.

The keyvalues can be written to disk using SaveToFile. These will be written to the game's scriptdata folder.

SaveToFile has an optional boolean rootless parameter (false by default). If true, the top root key won't be written, which matches the syntax of certain file formats such as VMF.

Iterating keys can be done using the following loop:

for (local dat = kv.m_Sub; dat; dat = dat.m_Peer)

Example

IncludeScript("keyvalues");

local kv = KeyValues("kv_test.cfg");
kv.Set("foo", 32);
kv.Set("bar", 621.69);

local subkv = KeyValues("test", kv);
subkv.Set("hello", true);
subkv.Set("world", "is dead");

kv.SaveToFile();

Which produces the following file named kv_test.cfg:

"kv_test.cfg"
{
	"foo" "32"
	"bar" "621.69"
	"test"
	{
		"hello" "1"
		"world" "is dead"
	}
}

Limitations

Reading support is not implemented yet.

The performance is slow, do not use this for any runtime work as it is very expensive.

No support for removing keys, though it should be simple to add.

License

Do whatever the hell you want

vscript_keyvalues's People

Contributors

ficool2 avatar

Stargazers

 avatar  avatar  avatar Joacoco avatar

Watchers

 avatar

Forkers

pmarkive

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.