> For the complete documentation index, see [llms.txt](https://walksy.gitbook.io/walksylib-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://walksy.gitbook.io/walksylib-docs/using/creating-an-option.md).

# Creating an Option

```java
Options.ofBoolean("Enabled", () -> enabled, true, value -> enabled = value)
    .description(OptionDescription.ofText(() -> "Turns the whole mod on or off."))
    .onChange(MyMod::refresh)
    .build();
```

For the full list of factories, see [Option Types](/walksylib-docs/using/option-types.md). This page covers the builder methods every option shares.

## Descriptions

```java
.description(OptionDescription.ofText(() -> "Shown when hovering the option."))
```

The text is a `Supplier`, so it can change at runtime. To draw something custom instead of text, use `OptionDescription.ofRender2D((graphics, panel) -> ...)`.

## Reacting to changes

```java
.onChange(() -> MyMod.rebuildCache())
```

Runs whenever the option's value changes.

## Availability

Grays out or hides an option depending on a condition:

```java
Options.ofColor("Enabled Color", () -> enabledColor, DEFAULT, value -> enabledColor = value)
    .availability(() -> customEnabledColor, AvailabilityMode.HIDE)
    .build();
```

| Overload                                          | Behaviour                                            |
| ------------------------------------------------- | ---------------------------------------------------- |
| `.availability(condition, "Helper text")`         | Grays out, and shows the helper text explaining why. |
| `.availability(condition, AvailabilityMode.HIDE)` | Hides the option when the condition is false.        |
| `.availability(condition, "Helper", mode)`        | Both.                                                |

`AvailabilityMode.GRAY_OUT` is the default.

## Save keys

Options are saved under their name. If you rename an option, keep users' settings by pinning the old key:

```java
Options.ofBoolean("Interpolate Colors", () -> lerp, false, value -> lerp = value)
    .saveKey("Interpolate Shield Color")
    .build();
```

{% hint style="info" %}
Save keys must be unique within a group.
{% endhint %}

## Warnings (booleans only)

Ask for confirmation before a toggle is turned on:

```java
Options.ofBoolean("Experimental", () -> experimental, false, value -> experimental = value)
    .warning(new Warning("Warning", "This feature is experimental. Are you sure?", null, null))
    .build();
```

The last two arguments are optional `Runnables` that run when the user picks **Yes** or **No**.
