GPC Developer Guides
Functions
Device Functions
here we will cover a few functions available within your code, these functions function description zen plus 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 polar sets the stick output at a given angle and radius with a high resolution value ✔️ ❌ 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 ✔️ ❌ clamp function the clamp() function clamps a value between an upper and lower bound clamp() enables selecting a middle value within a range of values between a defined minimum and maximum it takes three parameters a minimum value, a preferred value, and a maximum allowed value ✔️ ❌ 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 int days; int hours; int minutes; int seconds; int milliseconds; main { milliseconds = milliseconds + get rtime(); if(milliseconds >= 1000) { milliseconds = milliseconds 1000 seconds = seconds + 1; if(seconds == 60) { seconds = 0; minutes = minutes + 1; if(minutes == 60) { minutes = 0; hours = hours + 1; if(hours == 24) { hours = 0; days = days + 1; } } } } set val(trace 1, days); set val(trace 2, hours); set val(trace 3, minutes); set val(trace 4, seconds); set val(trace 5, milliseconds / 10); } 🔴 syntax get rtime ( ); ⚪ parameters none 🔵 returns the elapsed time, in milliseconds, between the main iteration main section get slot get slot returns an int value representing the current active slot of the cronus device int currentslot; init { currentslot = get slot(); } main { } 🔴 syntax getslot(); ⚪ parameters none 🔵 returns an int value representing 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 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 9 on cronus max plus or 0 8 on cronus zen 🔵 returns nothing get ctrlbutton get ctrlbutton returns the current control button the control button is set in the device tab within cronus pro's options window or the device tab of the cronus zen the enable remote control switch on device dictates which button it is set to get ctrlbutton(); 🔴 syntax get ctrlbutton( ); ⚪ parameters nothing 🔵 returns depending on the remote slot settings the value can be 0, 1 or 8 vm tctrl opcode 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 than changing this setting may cause instability within your script main { vm tctrl( 5); // run the vm every 5ms } 🔴 syntax vm tctrl( \<variable> ); ⚪ parameters \<variable> numeric value to add to the virtual machine base time range 9 10 🔵 returns nothing set polar sets the stick output at a given angle and radius with a high resolution value set polar(polar ls,250, 32000); 🔴 syntax¹ ² ³ set polar(stick,angle,radius); ⚪ parameters stick defined stick angle index point of the bit to be set with a range of 0 to 359 radius index point of the bit to be set with a range of 32768 to 32767 🔵 returns nothing set rgb sets the led on the zen to the supplied rgb color (red,green,blue) 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 index point of the bit to be set with a range of 0 255 green index point of the bit to be set with a range of 0 255 blue index point of the bit to be set 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 set hsb(300, 55, 70); 🔴 syntax¹ ² ³ set hsb( hue, saturation, brightness ); ⚪ parameters hue index point of the bit to be set with a range of 0 359 saturation index point of the bit to be set with a range of 0 100 brightness index point of the bit to be set with a range of 0 100 🔵 returns nothing clamp function the clamp function clamps x to the range \[min, max] int x = 10; main { if (event press(ps4 triangle)) x = clamp(x++, 10, 10); if (event press(ps4 cross)) x = clamp(x , 10, 10); set val(trace 1,x); } 🔴 syntax¹ ² ³ clamp(x, min, max) ⚪ parameters x— the number to clamp min— lower bound of range to which x is clamped minimum value returned max— upper bound of range to which x is clamped maximum value returned 🔵 returns returns min if x is less than min, max if x is greater than max, and x otherwise ;