LanguageUpdated 2026-07-24

User functions in GPC

Extract reusable synchronous calculations while respecting parameter, return, recursion, and combo-only timing rules.

Overview

User functions package repeated synchronous logic and calculations. Keep side effects clear and use parameters rather than hidden global coupling where practical.

Functions cannot recurse and cannot become timed sequences. Use combos for wait-based behavior.

Key facts

  • User functions cannot recurse.
  • wait is not valid in a user function.
  • A function completes synchronously before its caller continues.
  • Verify parameter and return constraints in the current compiler documentation.

GPC syntax examples

Examples are intentionally small. Replace identifiers only with values documented for your target.

Small reusable calculationexample.gpc
function within(value, low, high) {
    return value >= low && value <= high;
}

main {
    if (within(get_val(XB1_A), 50, 100)) {
        // in range
    }
}

Functions, commands, and terms

Names below are catalog entries, not guessed signatures. Open the official sources for current parameter and return-value details.

NameKindPurpose
functionkeyword

Declares a user-defined function.

returnkeyword

Ends a function and optionally supplies its result.

Common mistakes

A function calling itself directly or indirectly.

Putting wait in a function.

Using a function as though it runs asynchronously.

Official GPC sources

Use these first-party references to confirm exact syntax and runtime behavior for your installed firmware and Studio version.

Related GPC references