# DynamicValueRegistry

The `DynamicValueRegistry` manages dynamic values for widgets in **DynamicHUD**, supporting global (shared across mods) and local (mod-specific) registries. Use it to register `Supplier` instances for real-time data (e.g., FPS, player names) in the `init` method of your `DynamicHudIntegration`. This is what allows widgets to get and share dynamic values.

#### Usage

* **Local Registry**: Create with `DynamicValueRegistry(String modId)` or `DynamicValueRegistry(String modId, String registryId)`. Register with `registerLocal(String key, Supplier<?> supplier)`.
* **Global Registry**: Use `registerGlobal(String key, Supplier<?> supplier)` with `modid:key` format.
* **Retrieve Values**: Use `get(String key)` for local or `getValue(String registryID, String key)` for specific registries.

#### Example

```java
DynamicValueRegistry dvr = new DynamicValueRegistry("mymod");
dvr.registerLocal("abc", () -> "Hello!");
Supplier<?> result = dvr.get("abc");
```

#### Key Methods

* `registerGlobal(String key, Supplier<?> supplier)`: Adds a supplier to the global registry.
* `registerLocal(String key, Supplier<?> supplier)`: Adds a supplier to the local registry.
* `get(String key)`: Retrieves a local supplier.
* `getValue(String registryID, String key)`: Gets a supplier by registry ID and key.
* `getByIdSafe(String registryId)`: Gets a registry instance, throws `IllegalStateException` if not found.

{% hint style="warning" %}

* &#x20;Set `registryID` correctly in widgets (e.g., `DynamicValueRegistry.GLOBAL_ID` for global keys). Mismatches cause `null` values.
* It is suggested to use `modid:key` for global keys to avoid conflicts.
  {% endhint %}

{% hint style="danger" %}

* &#x20;Exception Thrown: `IllegalStateException` from `getByIdSafe` if registry ID is missing.
* &#x20;Exception Thrown: `IllegalArgumentException` from `getValue` if `registryID` or `key` is empty.
  {% endhint %}


---

# 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://tanishisherewith.gitbook.io/dynamic-hud/widget/dynamicvalueregistry.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.
