> For the complete documentation index, see [llms.txt](https://modeltrainscript.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://modeltrainscript.gitbook.io/docs/manual/automation/variables.md).

# Variables

Variables allow you to store numeric values (0–255) that can be used across your scripts. They are useful for counting events, tracking state, or creating more complex automation logic.

A typical use case is to count how many times a train has passed a sensor, or to coordinate behaviour between multiple scripts.

## Creating variables

Variables can be created from the [profile](/docs/manual/profile.md) screen under the automation section. Each variable has a name that you define and stores a single numeric value between 0 and 255.

## Using variables in scripts

Variables can be used in three ways within your [scripts](/docs/manual/automation/scripts.md):

### Actions

The [set variable](/docs/manual/automation/scripts/action/structure.md#set-variable) action allows you to modify a variable during script execution. You can choose from three operations:

* **Set to value** — Set the variable to a specific value (0–255).
* **Increase by 1** — Increment the variable by 1 (maximum 255).
* **Decrease by 1** — Decrement the variable by 1 (minimum 0).

### Conditions

You can use a variable as a condition in your scripts, sections, or actions. The condition checks whether a variable **equals** a specific value. This allows you to create branching logic — for example, only executing a section when a counter has reached a certain value.

### Execution events

Variables can be used as execution events to trigger a script when a variable reaches a specific value. This is useful for coordinating between scripts — one script can set a variable and another script can be triggered by that change.

## Layout display

Variables can be placed on your [layout](/docs/manual/layout.md) as an item. This displays the current value of the variable directly on the layout, making it easy to monitor variable state during automation.
