# Conditions System

***

## Conditions

Conditions are used by `WaitAction` and `BranchAction` to evaluate runtime state.

### BoolCondition

Evaluates a boolean field or property on a component.

| Property       | Description              |
| -------------- | ------------------------ |
| Target         | Component to read from   |
| Member         | Field or property name   |
| Expected Value | Value to compare against |

```csharp
// Check if a door is open
// Target: DoorController component
// Member: isOpen
// Expected Value: true
```

### ComparisonCondition

Compares a numeric value against a threshold.

| Property      | Description                                                         |
| ------------- | ------------------------------------------------------------------- |
| Target        | Component to read from                                              |
| Member        | Field or property name                                              |
| Operator      | Equal, NotEqual, LessThan, LessOrEqual, GreaterThan, GreaterOrEqual |
| Compare Value | Value to compare against                                            |

### PredicateCondition

Calls a parameterless method that returns bool.

| Property | Description                 |
| -------- | --------------------------- |
| Target   | Component to call method on |
| Method   | Method name to invoke       |

***

## Variable System

FlowOfAction includes a variable system for storing and comparing values between actions. This allows dynamic sequences that respond to game state without writing code.

### VariableStorage

A MonoBehaviour that stores variables. Can be used as a singleton (auto-created) or attached to specific GameObjects.

**Supported types:** Bool, Int, Float, String, Object (UnityEngine.Object), Vector2, Vector3, Color.

**Variable Change Event:**

```csharp
VariableStorage.Instance.OnVariableChanged += (name, type) => {
    Debug.Log($"Variable '{name}' of type {type} was changed");
};
```

**Usage from code:**

```csharp
// Singleton access
VariableStorage.Instance.SetInt("score", 100);
int score = VariableStorage.Instance.GetInt("score");

VariableStorage.Instance.SetBool("isComplete", true);
VariableStorage.Instance.ToggleBool("isComplete");

VariableStorage.Instance.SetVector3("spawnPoint", new Vector3(10, 0, 5));
Vector3 pos = VariableStorage.Instance.GetVector3("spawnPoint");
```

### SetVariable Action

Sets or modifies a variable in storage.

| Property      | Description                                                  |
| ------------- | ------------------------------------------------------------ |
| Variable Name | Name of the variable                                         |
| Variable Type | Bool, Int, Float, String, Object, Vector2, Vector3, or Color |
| Operation     | Set, Add, Multiply, Toggle, Append, or Lerp                  |

**Operations by type:** Bool (Set, Toggle) · Int/Float (Set, Add, Multiply) · String (Set, Append) · Object (Set) · Vector2/3 (Set, Add) · Color (Set, Lerp).

### CompareVariable Action

Compares a variable and executes conditional branches.

| Property      | Description                                                  |
| ------------- | ------------------------------------------------------------ |
| Variable Name | Name of the variable to compare                              |
| Variable Type | Bool, Int, Float, String, Object, Vector2, Vector3, or Color |
| Operator      | Equal, NotEqual, Greater, GreaterOrEqual, Less, LessOrEqual  |
| True Branch   | Actions to execute if condition is true                      |
| False Branch  | Actions to execute if condition is false                     |

**Example — purchase gate:**

```
Variable Name: coins
Variable Type: Int
Operator: GreaterOrEqual
Compare Value: 100

True Branch:
  - SetVariable (subtract 100 coins)
  - SpawnObject (give item to player)
  - PlayAudio (purchase sound)

False Branch:
  - SetUIText ("Not enough coins!")
  - PlayAudio (error sound)
```

**Common Patterns:**

**Counter-based triggers:**

```
SetVariable: enemiesDefeated, Int, Add, 1
CompareVariable: enemiesDefeated, Int, GreaterOrEqual, 10
  True Branch: Start next wave
```

**One-time events:**

```
CompareVariable: tutorialShown, Bool, Equal, false
  True Branch:
    - Show tutorial UI
    - SetVariable: tutorialShown = true
  False Branch:
    - (skip tutorial)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://beelabs-dev.gitbook.io/beelabs-docs/flow-of-action/conditions-system.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.
