---
title: Device Functions
slug: gpc/MnBy-gpc-scripting-device-functions
description: Here is the Device Functions.
icon: ◽
docTags: 
createdAt: 2021-12-08T18:02:03.000Z
---

Here we will cover a few functions available within your code, these functions&#x20;

| 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:

:::CodeblockTabs
GPC

```apex
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
}
```
:::

&#x20;🔴 **Syntax**

:::BlockQuote
**&#xD;**&#x67;et\_rtime();
:::

⚪&#x20;**Parameters**

**&#xD;**&#x4E;one

🔵&#x20;**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.

:::CodeblockTabs
GPC

```apex
int _currentSlot;
 
init {
     _currentSlot = get_slot();
 }
 
main {
 
}
```
:::

&#x20;🔴 **Syntax**

:::BlockQuote
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.

:::CodeblockTabs
GPC

```apex
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
 
}
```
:::

&#x20;🔴 **Syntax**

:::BlockQuote
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

:::CodeblockTabs
GPC

```apex
get_ctrlbutton();
```
:::

&#x20;🔴 **Syntax**

:::BlockQuote
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.

:::CodeblockTabs
GPC

```apex
main {
 
    vm_tctrl(-5); // Run the VM every 5ms
 
}
```
:::

🔴&#x20;**Syntax**

:::BlockQuote
**&#xD;**&#x76;m\_tctrl( \<timeout\_offset> );
:::

⚪&#x20;**Parameters**

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

🔵&#x20;**Returns**

**&#xD;**&#x4E;othing

# set\_rgb

`set_rgb` sets the LED colors on the Zen eyes or a Playstation controller based on the Hue, Saturation, and Brightness.

:::CodeblockTabs
GPC

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

&#x20;🔴 **Syntax**

:::BlockQuote
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.

:::CodeblockTabs
GPC

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

🔴 **Syntax**

:::BlockQuote
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&#x20;
\<brightness> : The brightness (amount of white) to use with a range of 0 - 100

🔵 **Returns**

Nothing

