Astral Realms Documentation Help

Menu Variables

Variables are mutable string values stored per-menu-instance. They act as local state, accessible as %variables_<name>% placeholders anywhere in the menu.

Declaration

Declare variables in the variables: map with their initial values:

variables: page: "0" mode: "buy" selected: "none"

Values are plain strings. Initial values are stored verbatim; runtime evaluation happens when set-variable runs (see below).

Reading Variables

Use %variables_<name>% in any field that supports placeholder substitution:

title: "<bold>Shop — %variables_mode%" name: "<yellow>Page %variables_page%"

If no menu-local variable matches the key, the lookup falls through to the global variables: map in config.yml, so the same namespace works for both scopes.

Updating Variables

Use the set-variable action:

actions: LEFT: - "[set-variable] page 0"

After the variable is updated, affected slots are automatically re-rendered.

Expression Syntax

Variable values support arithmetic and ternary expressions evaluated when set-variable runs.

Arithmetic — $e(...)

Wrap an arithmetic expression in $e(...). Placeholders inside the expression are resolved before evaluation; operands must evaluate to numbers.

Operators: +, -, *, /, ^, parentheses. The custom round(value, precision) function is also available.

- "[set-variable] count $e(%variables_count%+1)" - "[set-variable] score $e(%parameters_base%*%variables_multiplier%)" - "[set-variable] avg $e(round((%variables_a%+%variables_b%)/2, 2))"

The result is returned as an integer when the value is whole, otherwise as a double.

Ternary

<condition> ? <true-value> : <false-value>

The condition uses the same operators as the compare requirement: ==, !=, <, >, <=, >=.

- "[set-variable] mode %variables_mode% == buy ? sell : buy" - "[set-variable] page %variables_page% > 0 ? $e(%variables_page%-1) : 0"

Ternary expressions can be combined with $e(...) to compute branches.

Example: Tab Navigation

variables: tab: "weapons" items: weapons-tab: slot: 1 item-stack: material: DIAMOND_SWORD name: "<yellow>Weapons" actions: LEFT: - "[set-variable] tab weapons" - "[refresh]" armor-tab: slot: 2 item-stack: material: DIAMOND_CHESTPLATE name: "<yellow>Armor" actions: LEFT: - "[set-variable] tab armor" - "[refresh]" content-item: slot: 22 item-stack: material: STONE name: "Tab: %variables_tab%"

Example: Counter with Bounds

variables: qty: "1" items: plus: slot: 6 item-stack: material: LIME_DYE name: "<green>+" actions: LEFT: - "[set-variable] qty %variables_qty% < 64 ? $e(%variables_qty%+1) : 64" - "[refresh-slot] 4" minus: slot: 2 item-stack: material: RED_DYE name: "<red>-" actions: LEFT: - "[set-variable] qty %variables_qty% > 1 ? $e(%variables_qty%-1) : 1" - "[refresh-slot] 4" display: slot: 4 item-stack: material: PAPER name: "Quantity: <white>%variables_qty%"
Last modified: 25 July 2026