> 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/gpc-developer-guide/functions/internal-functions/device-functions.md).

# Device Functions

| **Function**    | **Description**                                                   |
| --------------- | ----------------------------------------------------------------- |
| get\_rtime      | Returns the elapsed time between main iterations in milliseconds. |
| get\_slot       | Returns the active slot number.                                   |
| load\_slot      | Loads a specified slot.                                           |
| get\_ctrlbutton | Returns the identifier of the controller button.                  |
| vm\_tctrl       | Sets the vm timeout for the next iteration.                       |
| set\_rgb        | Sets the LED on the ZEN to the supplied RGB color.                |
| set\_hsb        | Sets the LED on the ZEN to the supplied HSB color.                |

***

### get\_rtime

get\_rtime returns the elapsed time between the current and previous iteration of the main function. The value returned is in milliseconds.

You can see this function in action by using this counter script:

Code-Snippet

```
int days;
int hours;
int minutes;
int seconds;
int milliseconds;

main {
    milliseconds += get_rtime();

    if(milliseconds >= 1000) { // Check if we have 1000 or more milliseconds passed
        milliseconds -= 1000 // Subtract 1000 from the milliseconds value, this ensures accuracy as the timing may not be precise
        seconds++; // Increment the seconds counter
    }

    if(seconds == 60) { // Check if 60 seconds has passed (1 minute)
        seconds = 0; // Reset the seconds counter to 0
        minutes++; // Increment the minutes counter
    }

    if(minutes == 60) { // Check if 60 minutes has passed (1 hour)
        minutes = 0; // Reset the minutes counter to 0
        hours++; // Increment the hours counter
    }

    if(hours == 24) { // Check if 24 hours has passed (1 day)
        hours = 0; // Reset the hours counter to 0
        days++; // Increment the days counter
    }

    set_val(TRACE_1, milliseconds); // Output the milliseconds to TRACE_1
    set_val(TRACE_2, seconds); // Output the seconds to TRACE_2
    set_val(TRACE_3, minutes); // Output the minutes to TRACE_3
    set_val(TRACE_4, hours); // Output the hours to TRACE_4
    set_val(TRACE_5, days); // Output the days to TRACE_5
}
```

Syntax

get\_rtime();

Parameters

None

Returns

The elapsed time, in milliseconds, since the last main iteration, default is 10ms but is dependant on the use of vm\_tctrl

***

### get\_slot

get\_slot returns an int value representing the current active slot of the Cronus Device.

Code-Snippet

```
int _currentSlot;

init {
    _currentSlot = get_slot();
}

main {

}
```

Syntax

get\_slot();

Parameters

None

Returns

An int value represents the current active slot of the Cronus Device.

***

### load\_slot

load\_slot will attempt to load the slot number specified within its parameter. If there is no script current stored in the specified slot, then it will unload the current slot and load slot 0 of the device.

Code-Snippet

```
main {

    if(event_press(XB1_RB)) // if RB / R2 is pressed...
        load_slot(5); // Load slot 5

    if(event_press(XB1_LB)) // if LB / L2 is pressed...
        load_slot(0); // Unload current slot and load slot 0

}
```

Syntax

load\_slot ( \<slot\_number> );

Parameters

\<slot\_number> : A value which represents a slot number to load with a range of 0 - 8.

Returns

Note: Any code after this statement will not be executed as the new slot is loaded immediately and any changes made by the current script will be kept during the first execution of the loaded slot

***

### get\_ctrlbutton

get\_ctrlbutton returns the current control button. The control button is set in the Device Tab of the Zen Studio this basically lets you know which button combo is configured to switch slots using the remote slot configuration.

Code-Snippet

```
get_ctrlbutton();
```

Syntax

get\_ctrlbutton();

Parameters

Nothing

Returns

Depending on the remote slot settings the value can be 0, 1 or 8

***

### vm\_tctrl

vm\_tctrl sets the virtual machine timeout for the next iteration. By default, the virtual machine runs the main loop every 10 milliseconds as it aids stability. You can however adjust how often each main iteration is run. Just be aware that changing this setting may cause instability within your script.

Code-Snippet

```
main {

    vm_tctrl(-5); // Run the VM every 5ms

}
```

Syntax

vm\_tctrl( \<timeout\_offset> );

Parameters

\<timeout\_offset> : Numeric value to add to the Virtual Machine base time. Range -9 \~ 30

Returns

Nothing

***

### set\_rgb

set\_rgb sets the LED colors on the Zen eyes or a Playstation controller based on the Hue, Saturation, and Brightness.

Code-Snippet

```
set_rgb(255, 0, 0) // red
set_rgb(0, 255, 0)// green
set_rgb(0, 0, 255) // blue
```

Syntax

set\_rgb( \<red> , \<green> , \<blue> );

Parameters

\<red> : The amount of red to use with a range of 0 - 255

\<green> : The amount of green to use with a range of 0 - 255

\<blue> : The amount of blue to use with a range of 0 - 255

Returns

Nothing

***

### set\_hsb

set\_hsb sets the LED colors on the Zen eyes or a Playstation controller based on the Hue, Saturation, and Brightness.

Code-Snippet

```
set_hsb(300, 55, 70);
```

Syntax

set\_hsb( \<hue>, \<saturation>, \<brightness> );

Parameters

\<hue> : The hue (color on a 360 degree wheel) to use with a range of 0 - 359

\<saturation> : The saturation (amount of color) to use with a range of 0 - 100

\<brightness> : The brightness (amount of white) to use with a range of 0 - 100

Returns

Nothing


---

# 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/gpc-developer-guide/functions/internal-functions/device-functions.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.
