> For the complete documentation index, see [llms.txt](https://guide.cronuszen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.cronuszen.com/gpcscripting/gpc-script-guide/reference/additional-built-ins/device-timing-remapper-and-bvar-built-ins.md).

# Device, timing, remapper, and BVAR built-ins

These functions affect VM timing, active slots, device settings, LEDs, or persistent binary-variable storage. Treat slot changes and persistent writes as deliberate user actions, never background work at the base of `main`.

***

#### `get_rtime`

Returns the elapsed time between the current and previous `main` iterations.

**Syntax**

```gpc
elapsed_ms = get_rtime();
```

**Parameters**

None.

**Returns**

Elapsed milliseconds. The usual value is near the VM interval, but it can change with timing control and runtime conditions.

**Example**

{% code title="get-rtime.gpc" %}

```gpc
int elapsed_ms;

main {
    elapsed_ms = elapsed_ms + get_rtime();
    if(elapsed_ms >= 1000) elapsed_ms = elapsed_ms - 1000;
    set_val(TRACE_1, elapsed_ms);
}
```

{% endcode %}

Subtract the threshold instead of resetting to zero when accumulated timing should retain overshoot.

***

#### `get_slot`

Returns the currently active Zen memory slot.

**Syntax**

```gpc
slot = get_slot();
```

**Parameters**

None.

**Returns**

The active slot number.

**Example**

{% code title="get-slot.gpc" %}

```gpc
int active_slot;

init {
    active_slot = get_slot();
}

main {
    set_val(TRACE_1, active_slot);
}
```

{% endcode %}

Refresh the cached value only when the script design has a reason to expect a slot-state change.

***

#### `load_slot`

Immediately attempts to load a slot. Slot `0` unloads the current programmed slot; the accepted range is `0..8`.

**Syntax**

```gpc
load_slot(slot);
```

**Parameters**

* `slot`: `0..8`.

**Returns**

Nothing. Loading occurs immediately, so code after the call must not be relied on.

**Example**

{% code title="load-slot.gpc" %}

```gpc
main {
    if(get_ival(PS5_L2) && event_press(PS5_OPTIONS)) {
        load_slot(2);
    }
}
```

{% endcode %}

Use an intentional chord to prevent accidental slot changes.

***

#### `get_ctrlbutton`

Returns the configured remote slot-control button mode from the Zen device settings.

**Syntax**

```gpc
control_mode = get_ctrlbutton();
```

**Parameters**

None.

**Returns**

The configured control-button mode; the supplied Live documentation identifies values `0`, `1`, and `8`.

**Example**

{% code title="get-ctrlbutton.gpc" %}

```gpc
int control_mode;

init {
    control_mode = get_ctrlbutton();
}

main {
    set_val(TRACE_1, control_mode);
}
```

{% endcode %}

Treat the result as device configuration data, not as a controller report identifier.

***

#### `vm_tctrl`

Applies an offset to the VM interval for the next iteration.

**Syntax**

```gpc
vm_tctrl(timeout_offset);
```

**Parameters**

* `timeout_offset`: compiler-accepted range `-9..30` relative to the normal interval.

**Returns**

Nothing.

**Example**

{% code title="vm-tctrl.gpc" %}

```gpc
main {
    vm_tctrl(-5);
    set_val(TRACE_1, get_rtime());
}
```

{% endcode %}

Shorter intervals increase VM work and may reduce stability. Measure VM load and controller behavior before keeping a non-default value.

***

#### `set_rgb`

Sets the Zen or controller LED color with red, green, and blue components.

**Syntax**

```gpc
set_rgb(red, green, blue);
```

**Parameters**

* `red`, `green`, `blue`: each `0..255`.

**Returns**

Nothing.

**Example**

{% code title="set-rgb.gpc" %}

```gpc
int feedback_dirty = TRUE;

main {
    if(feedback_dirty) {
        set_rgb(87, 151, 209);
        feedback_dirty = FALSE;
    }
}
```

{% endcode %}

Render on a state change instead of rewriting the same color every cycle.

***

#### `set_hsb`

Sets the Zen or controller LED color using hue, saturation, and brightness.

**Syntax**

```gpc
set_hsb(hue, saturation, brightness);
```

**Parameters**

* `hue`: `0..360` degrees.
* `saturation`: `0..100` percent.
* `brightness`: `0..100` percent.

**Returns**

Nothing.

**Example**

{% code title="set-hsb.gpc" %}

```gpc
init {
    set_hsb(210, 60, 80);
}
```

{% endcode %}

***

#### `get_info`

Queries a value from the active mouse-and-keyboard profile or related Live device state.

**Syntax**

```gpc
value = get_info(selector);
```

**Parameters**

* `selector`: numeric selector accepted by the exact Live build.

**Returns**

The selected information value.

**Example**

{% code title="get-info.gpc" %}

```gpc
int profile_value;

main {
    profile_value = get_info(0);
    set_val(TRACE_1, profile_value);
}
```

{% endcode %}

Use the documented Zen Studio Live selector constants whenever possible. Confirm any raw numeric selector against the intended Live build before relying on its meaning.

***

#### `set_remapper`

Changes one entry in the device-level remapper. This is different from a script `remap` declaration because it modifies device configuration.

**Syntax**

```gpc
set_remapper(identifier_from, identifier_to);
```

**Parameters**

* `identifier_from`: `BUTTON_MIN..BUTTON_MAX`.
* `identifier_to`: `BUTTON_MIN..BUTTON_MAX`.

**Returns**

Nothing.

**Example**

{% code title="set-remapper.gpc" %}

```gpc
int remap_saved;

main {
    if(!remap_saved && get_ival(PS5_L2) && event_press(PS5_OPTIONS)) {
        set_remapper(PS5_CROSS, PS5_CIRCLE);
        save_eeprom();
        remap_saved = TRUE;
    }
}
```

{% endcode %}

Use a guarded, explicit action. A device remapper change can affect scripts beyond the current slot.

***

#### `save_eeprom`

Persists changed device settings to EEPROM.

**Syntax**

```gpc
save_eeprom();
```

**Parameters**

None.

**Returns**

Nothing.

**Example**

{% code title="save-eeprom.gpc" %}

```gpc
int device_setting_dirty;

main {
    if(event_press(PS5_CROSS)) device_setting_dirty = TRUE;

    if(device_setting_dirty && event_press(PS5_OPTIONS)) {
        save_eeprom();
        device_setting_dirty = FALSE;
    }
}
```

{% endcode %}

{% hint style="warning" %}
EEPROM has a finite write life. Never call this unconditionally in `main`.
{% endhint %}

***

#### `get_bvar`

Reads one indexed BVAR value on the 32-bit target.

**Syntax**

```gpc
value = get_bvar(index);
```

**Parameters**

* `index`: `0..1023`.

**Returns**

The value stored at the selected index.

**Example**

{% code title="get-bvar.gpc" %}

```gpc
define PROFILE_GAIN_INDEX = 40;

int profile_gain;

init {
    profile_gain = get_bvar(PROFILE_GAIN_INDEX);
    if(profile_gain < 0 || profile_gain > 200) profile_gain = 100;
}
```

{% endcode %}

Validate loaded data before using it, and reserve index ranges so unrelated records cannot overlap.

***

#### `set_bvar`

Writes one indexed BVAR value on the 32-bit target.

**Syntax**

```gpc
set_bvar(index, value);
```

**Parameters**

* `index`: `0..1023`.
* `value`: current-target signed integer expression. Device-test storage width and signed round trips for the intended firmware.

**Returns**

Nothing.

**Example**

{% code title="set-bvar.gpc" %}

```gpc
define PROFILE_GAIN_INDEX = 40;

int profile_gain = 100;
int dirty;

main {
    if(event_press(PS5_UP)) {
        profile_gain = min(profile_gain + 1, 200);
        dirty = TRUE;
    }

    if(dirty && event_press(PS5_OPTIONS)) {
        set_bvar(PROFILE_GAIN_INDEX, profile_gain);
        dirty = FALSE;
    }
}
```

{% endcode %}

Use named schema constants, bounds-check computed indexes, and write only on an explicit save/change event.


---

# 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, and the optional `goal` query parameter:

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/reference/additional-built-ins/device-timing-remapper-and-bvar-built-ins.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
