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.
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.
functionkeywordDeclares a user-defined function.
returnkeywordEnds 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
Build conditions and loops with comparison, logical, arithmetic, assignment, if, else, while, for, break, and continue.
ExecutionGPC combos, wait, and callAuthor timed first-level combo steps with legal wait durations and compose sequences with combo-only call.
LanguageMath and bit functionsUse the official integer math helpers and verified bit-field functions within GPC numeric limits.