> For the complete documentation index, see [llms.txt](https://vypxl.gitbook.io/scar/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vypxl.gitbook.io/scar/builtin-features/config.md).

# Config

The `Scar::Config` module provides an easy way of storing key-value configuration. It uses [Util](/scar/builtin-features/util.md) to save and load the config file.

To use it, you have to declare your configuration structure. To do that, you can use the `Scar::Config#define_standards` macro at toplevel. Just provide a hash with names and default values for every config entry. The values have to be of any type in the `YAML::Any` union.

```ruby
Scar::Config.define_standards({
    resolution_w: 1600,
    resolution_h: 900,
    name: "ProPlayer9001",
    skills: [false, true, false, false],
})
```

There are methods for all sorts of config manipulation. You can..

* `reset(key)`any value by key to its standard
* `load_standards` to reset all values
* `[](key)` to access a value by key (returns the default value if it is not present)
* `[]=(key, value)` to set a value
* `save(fname)` to save the current configuration to a file (via [Util](/scar/builtin-features/util.md)#write\_file)
* `load(fname)` to load a configuration from a file (via [Util](/scar/builtin-features/util.md)#read\_file)
* `dump` the yaml representation of the current configuration for debugging.

```ruby
Config.load("config.yml")
Logger.info "the window width is #{Config[:resolution_w]}"
Config[:name] = "ProPlayer1337"
Config.reset(:skills)
Config.save("config.yml")
```
