# Working with Config

This guide shows how to use configuration inside a feature.

The example extends `HelloWorldFeature` to use configurable values.

***

### Overview

Features receive configuration through `ConfigProvider`.

The config is:

* initialized during the OMS lifecycle
* accessible via `config` property
* used to control feature behavior

***

### 1. Add config fields

Extend your config with additional values:

```kotlin
builder.push(CHelloWorldFeature.NAME)

val enabled = builder.define("enabled", true)

val message = builder.define(
    "message",
    "hello world"
)

val repeat = builder.defineInRange(
    "repeat",
    1,
    1,
    10
)

builder.pop()

CHelloWorldFeature(enabled, message, repeat)
```

Update your config class:

```kotlin
class CHelloWorldFeature(
    private val enabledValue: ForgeConfigSpec.BooleanValue,
    private val messageValue: ForgeConfigSpec.ConfigValue<String>,
    private val repeatValue: ForgeConfigSpec.IntValue
) : FeatureConfig {

    override val name: String = NAME

    override fun isEnabled(): Boolean = enabledValue.get()

    override fun enable() = enabledValue.set(true)

    override fun disable() = enabledValue.set(false)

    fun message(): String = messageValue.get()

    fun repeat(): Int = repeatValue.get()

    override fun getConfigData(): Map<String, Any> {
        return mapOf(
            "enabled" to enabledValue.get(),
            "message" to messageValue.get(),
            "repeat" to repeatValue.get()
        )
    }

    companion object {
        const val NAME = "hello_world"
    }
}
```

***

### 2. Use config in the feature

```kotlin
override fun onOmsStarted(
    event: OMSLifecycle.StartingEvent,
    context: AddonContext
) {
    repeat(config.repeat()) {
        println(config.message())
    }
}
```

Now the output is fully controlled by config.

***

### 3. Enable / disable behavior

Feature execution depends on:

```kotlin
if (config.isEnabled()) {
    // feature logic runs
}
```

OMS already respects this in:

* ticking (`onOmsTick`)
* feature lifecycle

***

### 4. Access config in commands

```kotlin
println(feature.config.message())
```

Commands always use the current config state.

***

### Notes

* Config is provided through `ConfigProvider`
* Access via `config` inside the feature
* Config values are read on demand
* Changes may require reload depending on setup


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://conboi.gitbook.io/oms-wiki/developer-guide/implementation-guides/working-with-config.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
