System Functions

System documentation covers debug output and script organization features that help users build and tune GPC3 scripts.

Quick Reference

Feature Signature / Syntax Use
printf int printf(string format, ...) Print debug output
User functions function [type] name(args) { ... } Reuse script logic
Preprocessor #define, #include, conditionals Compile-time constants and shared code

printf

gpc
int printf(string format, ...);

Prints formatted debug output. Use it while building and tuning scripts, especially for toggles, mode changes, timing checks, and analog values.

Parameter Type Description
format string Format string with optional specifiers
... any supported values Values inserted into the format string

Common format specifiers:

Specifier Value
%d Integer
%f Fixed-point/decimal value
%s String
%b Boolean-style value
%% Literal percent sign

gpc
int mode = 1;
fix32 sensitivity = 1.20;
bool enabled = TRUE;

init {
    printf("Script loaded");
    printf("Mode: %d", mode);
    printf("Sensitivity: %f", sensitivity);
    printf("Enabled: %b", enabled);
    printf("Progress: 50%%");
}

Debugging a Toggle

gpc
bool diagnostic_logging = FALSE;

main {
    if (event_active(BUTTON_11)) {
        diagnostic_logging = !diagnostic_logging;
        printf("Diagnostic logging: %b", diagnostic_logging);
    }
}

User Functions

gpc
function fix32 function_name(fix32 value) {
    return value;
}

Use functions for reusable calculations and script helpers. Keep them small and focused so scripts remain easy to test.

For compatible scripts, the return type and parameter types may be omitted; omitted types default to int.

gpc
function add(a, b) {
    return a + b;
}
gpc
function fix32 apply_deadzone(fix32 value, fix32 zone) {
    if (abs(value) < zone) {
        return 0.0;
    }

    return value;
}

main {
    set_val(STICK_2_X, apply_deadzone(get_val(STICK_2_X), 8.0));
}

Multiple Parameters

gpc
function fix32 scale_axis(fix32 value, fix32 scale) {
    return clamp(value * scale, -100.0, 100.0);
}

main {
    set_val(STICK_2_X, scale_axis(get_val(STICK_2_X), 1.15));
    set_val(STICK_2_Y, scale_axis(get_val(STICK_2_Y), 1.15));
}

Preprocessor

GPC3 supports common preprocessor directives for constants, shared include files, and compile-time switches.

gpc
#define TEST_HOLD_MS 100
#define USE_DEBUG

#ifdef USE_DEBUG
    #define DEBUG_PRINT(v) printf(v)
#endif

Supported directive families include:

Directive Use
#define Define constants or simple macros
#undef Remove a definition
#include Include shared script code
#if, #ifdef, #ifndef Compile conditional blocks
#else, #endif Complete conditional blocks

Bit Helpers

Function Use
set_bit(variable, index) Set one bit in a variable or array element
clear_bit(variable, index) Clear one bit
test_bit(value, index) Test one bit
set_bits(variable, value, index, mask) Replace a masked bit field
get_bits(value, index, mask) Read a masked bit field

The supported bit index range is 0 through 15. The mutating calls require a variable or array element as their first argument.

Tunable Constants

gpc
#define TEST_BUTTON BUTTON_15
#define TEST_HOLD_MS 100

combo OutputTest {
    set_val(TEST_BUTTON, 100);
    wait(TEST_HOLD_MS);
    set_val(TEST_BUTTON, 0);
}

Notes

  • Use printf() to validate behavior, then reduce high-frequency logging once the script is stable.
  • Put user-tunable settings near the top of the file.
  • Prefer small helper functions over repeating the same math in several places.
  • Use includes for shared constants and helpers that are reused across multiple scripts.