# RF Context

## Reality Context

`Reality Context` is the base object used to pass data during gameplay execution.

It allows systems to:

* share information between actions,
* attach flags to execution,
* provide context-aware behavior.

> All execution contexts inherit from this base class.

***

## Overview

| Feature         | Description                                           |
| --------------- | ----------------------------------------------------- |
| Data Container  | Holds execution-related data                          |
| Flags System    | Supports simple flag-based logic                      |
| Extendable      | Can be extended for specific systems                  |
| Used Everywhere | Used by functions, phases, teams, and gameplay events |

***

## Flags System

### Functions

| Name     | Type     | Description                            | Inputs      | Outputs |
| -------- | -------- | -------------------------------------- | ----------- | ------- |
| Has Flag | Callable | Checks if a flag exists in the context | Flag (Name) | Boolean |

***

### Properties

| Name         | Type  | Description                            |
| ------------ | ----- | -------------------------------------- |
| Context Flag | Array | List of flags attached to this context |

***

### Usage

| Example      | Description                       |
| ------------ | --------------------------------- |
| "IsRespawn"  | Mark execution as a respawn event |
| "IsOvertime" | Identify overtime logic           |
| "IsBonus"    | Trigger bonus-specific behavior   |

***

## Reality Execution Context

`Reality Execution Context` extends the base context with execution results.

It is used when running gameplay logic.

***

### Properties

| Name              | Type    | Description                                |
| ----------------- | ------- | ------------------------------------------ |
| Execution Success | Boolean | Indicates whether execution succeeded      |
| Error Message     | String  | Contains error details if execution failed |

***

### Usage

| Use Case           | Description                              |
| ------------------ | ---------------------------------------- |
| Validate execution | Mark success or failure                  |
| Debug errors       | Store error messages                     |
| Control flow       | Stop or modify execution based on result |

***

## Reality Game Phase Context

`Reality Game Phase Context` is used during phase execution.

It provides access to the current phase.

***

### Properties

| Name       | Type   | Description                              |
| ---------- | ------ | ---------------------------------------- |
| Game Phase | Object | The phase associated with this execution |

***

### Usage

| Use Case             | Description                             |
| -------------------- | --------------------------------------- |
| Access current phase | Retrieve phase data during execution    |
| Phase-based logic    | Run different logic depending on phase  |
| Debug phase flow     | Inspect which phase triggered execution |

***

## Reality Team Context

`Reality Team Context` is used during team-related execution.

It provides access to the current team instance.

***

### Properties

| Name          | Type   | Description                             |
| ------------- | ------ | --------------------------------------- |
| Team Instance | Object | The team associated with this execution |

***

### Usage

| Use Case            | Description                        |
| ------------------- | ---------------------------------- |
| Team-specific logic | Run logic only for a specific team |
| Score handling      | Access team score or data          |
| Team-based events   | React to team changes or actions   |

***

## Context Hierarchy

| Context                    | Inherits From             | Purpose                        |
| -------------------------- | ------------------------- | ------------------------------ |
| Reality Context            | —                         | Base data container            |
| Reality Execution Context  | Reality Context           | Adds execution result handling |
| Reality Game Phase Context | Reality Execution Context | Adds phase reference           |
| Reality Team Context       | Reality Execution Context | Adds team reference            |

***

## Typical Use Cases

| Use Case          | Recommended Context        |
| ----------------- | -------------------------- |
| Generic execution | Reality Execution Context  |
| Phase-based logic | Reality Game Phase Context |
| Team-based logic  | Reality Team Context       |
| Flag-based logic  | Reality Context            |

***

## Best Practices

| Recommendation                  | Description                                |
| ------------------------------- | ------------------------------------------ |
| Use the right context type      | Choose the most specific context available |
| Use flags for lightweight logic | Avoid creating too many context types      |
| Keep context minimal            | Only store necessary data                  |
| Use execution success carefully | Control flow based on result               |

***

## Notes

| Topic       | Note                                          |
| ----------- | --------------------------------------------- |
| Core System | Contexts are used across the entire framework |
| Lightweight | Designed to be simple data carriers           |
| Extendable  | You can create custom context types           |
| Optional    | Not all executions require a context          |

***

## Related Pages

| Page               | Description                                   |
| ------------------ | --------------------------------------------- |
| Reality Function   | Uses execution context when executing actions |
| Reality Game Phase | Provides phase context during execution       |
| Reality Team       | Provides team context for team-based logic    |
| Reality Game Data  | Uses contexts in gameplay event execution     |

***

## Summary

| Item        | Description                            |
| ----------- | -------------------------------------- |
| What it is  | Base system for passing execution data |
| Main usage  | Used in functions, phases, and events  |
| Key feature | Supports flags and execution state     |
| Variants    | Execution, Phase, and Team contexts    |


---

# 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://beyond-sandbox.gitbook.io/realitysdk/documentation/gamemode/reality-function/rf-context.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.
