# Rules

Rules are local boolean values on a SparkEntity. They represent simple true/false states like "is dead", "can move", "is grounded", "is in combat", and so on.

## What Rules Are For

Each SparkEntity can have a set of rules attached to it through the **RulesEntity** component. These rules act as flags that other systems and scripts read to determine what the entity is currently allowed to do or what state it is in.

For example:

* A "DEAD" rule set to `true` means the entity is dead. The UI system checks this and blocks opening panels while dead.
* A "CAN\_MOVE" rule set to `false` prevents the character from moving (used during stuns, knockdowns, or ability casts).
* A "GROUNDED" rule tracks whether the character is on the ground.

## Rule Entries

In the Spark Editor under the **Rules** tab, each **RuleEntry** defines a rule with:

| Field          | Description                                                         |
| -------------- | ------------------------------------------------------------------- |
| `key`          | A unique string identifier (e.g., "DEAD", "CAN\_MOVE", "GROUNDED")  |
| `defaultValue` | The starting value when no modifications are active (true or false) |

## How Rules Work at Runtime

Rules are set by scripts at runtime. When something happens in the game (a character dies, gets stunned, lands on the ground), the responsible system sets the appropriate rule value on the entity.

Other systems then check these rules to decide what to do. For example, the character controller checks the "CAN\_MOVE" rule before allowing movement. The UI checks the "DEAD" rule before opening a panel.

## Rule Modifications

Rules support temporary modifications with priorities. Multiple systems can modify the same rule at the same time, and the highest-priority modification wins.

For example, a stun ability might set "CAN\_MOVE" to `false` with a duration of 3 seconds and a priority of 10. When the duration expires, the modification is automatically removed and the rule returns to its previous value.

This prevents conflicts where one system sets a rule to `false` and another sets it back to `true` at the wrong time. The priority system ensures a clean resolution.

## Rule Subscriptions

Systems can subscribe to rule changes and get notified when a rule value changes on a specific entity. This is how UI elements and other reactive systems stay in sync with entity state.


---

# 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://docs.sparkframework.dev/documentation/user-guide/core-systems/rules.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.
