> For the complete documentation index, see [llms.txt](https://guide.cronuszen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.cronuszen.com/gpcscripting/gpc-script-guide/troubleshooting/compiler-diagnostic-catalog/semantic-errors-gpc40xx.md).

# Semantic errors (GPC40xx)

### GPC4000 — Redefinition

```
Redefinition of {kind} '{name}' detected (previously declared on {location})
Duplicate parameter name '{name}' in function '{function}'
```

**Severity:** Error

The same name is declared twice as the same kind of symbol — two variables, two functions, two defines with the same name, or two parameters of one function. The message points at the earlier declaration.

***

### GPC4001 — Naming Conflict

```
'{name}' is already declared on {location}
Function '{name}' conflicts with built-in function '{name}'
{Kind} '{name}' conflicts with {other kind} '{name}' declared on {location}
```

**Severity:** Error

The same name is used where the compiler requires uniqueness. Variables, definitions, enum members, and const-data names share the data-symbol namespace, so a define and variable cannot reuse one name. Function names and combo names are resolved separately from that namespace, while built-in names and language keywords remain reserved. A user function named after almost any built-in (`set_val`, `get_val`, ...) also triggers this diagnostic; only `min`, `max`, and `clamp` get special handling instead (see GPC4025).

***

### GPC4002 — Undefined Identifier

```
'{name}' is not defined
Undefined variable: {name}
No variable or const array named '{name}' could be found.
```

The first may carry the suggestion `Did you mean '{other}'?`.

**Severity:** Error

An identifier is referenced but no variable, define, enum member, const array, function parameter, or built-in constant with that name exists. Check spelling and case — GPC names are case-sensitive; the compiler suggests the closest existing name when one is similar enough.

```c
int speed;
main {
    sped = 100;   // GPC4002 — Did you mean 'speed'?
}
```

***

### GPC4003 — Scoped Variable Not Supported

```
Variables should be declared at top level
```

**Severity:** Error

A variable is declared inside a block (function body, `main`, `if` body, ...). GPC has no block scope — all variables must be declared at the top level of the script.

```c
main {
    int count;   // GPC4003 — move above main
}
```

***

### GPC4004 — Function Used as Value

```
'{name}' is a function and cannot be used as a variable or value
'{name}' is not a function and cannot be called
```

**Severity:** Error

Either a function name is used where a value is expected (e.g. `x = myFunc;` without parentheses), or the inverse: a value symbol (variable, define, ...) is called like a function (`myVar()`).

***

### GPC4005 — Invalid Control Flow

```
'break' is not allowed outside a loop or switch
'continue' is not allowed outside a loop
Cannot use 'return' outside of a function
```

**Severity:** Error

A control-flow statement appears in a context where it has no meaning. Note that `continue` is not allowed inside a `switch` unless the switch itself is inside a loop, and `return` is only valid inside a user-defined function body.

***

### GPC4006 — Invalid Array Access

```
2D array access not supported in this context
```

**Severity:** Error

Two-dimensional index syntax (`name[a][b]`) is applied to something that is not a 2D const array. Only `const` arrays declared with two bracket pairs support two indexes.

***

### GPC4007 — Invalid Assignment Target

```
Invalid assignment target
Increment/decrement requires a variable
'{name}' is {a constant/a define/...} and cannot be used as a variable
```

**Severity:** Error

The left side of an assignment (or the operand of `++`/`--`) is not something writable: it is a literal, an expression, a define, an enum member, a const array, or a built-in constant. Only variables and array-slot accesses can be assigned.

***

### GPC4009 — Invalid Function Parameter

```
'{name}' is {kind} and cannot be used as a combo name in {function}(). Only combo names are allowed here.
The argument to {function}() must be a combo name, not an expression.
```

**Severity:** Error

The argument to a combo keyword (`combo_run`, `combo_stop`, `combo_pause`, `combo_running`, ...) is not the name of a declared combo — it is a variable, function, define, or a computed expression. Combo references are resolved at compile time and must be plain combo names.

***

### GPC4010 — Invalid Combo Usage

```
'{name}' is a combo and cannot be used as a variable or value
'{name}' is a combo and cannot be called as a function. Use combo keywords like combo_run({name}) instead.
'{keyword}' is only allowed inside combos. Use '{keyword}' within a combo block.
'{keyword}' is only allowed at the root level of combos, not inside nested blocks (if, while, for, etc.).
```

**Severity:** Error

A combo name or combo-only keyword is used in the wrong place. Combos are not values and not functions; combo-only keywords such as `wait()` and `call()` may only appear directly at the root level of a combo body — not in `main`, and not nested inside an `if`/`while`/`for` within the combo.

***

### GPC4011 — Too Many Arguments

```
Function '{name}' expects {n} argument(s), but got {m}
```

**Severity:** Error

A call passes more arguments than the function declares.

***

### GPC4012 — Too Many Parameters

```
Function '{name}' declares too many parameters
```

**Severity:** Error

A `function` declaration has more parameters than the compiler accepts.

***

### GPC4013 — Variable Declared in `for` Initializer

```
Variables should be declared at top level
```

**Severity:** Error

A `for` loop header declares a variable in its initializer clause (`for(int i = 0; ...)`). GPC has no block scope — declare the counter at top level and only assign it in the header.

```c
int i;
main {
    for(i = 0; i < 4; i++) { }   // OK
}
```

***

### GPC4014 — `for` Initializer Shadows a Global

```
For loop initializer '{name}' shadows {kind} '{name}' declared on {location}.
```

**Severity:** Error

The name used in a `for` initializer collides with an existing global variable, definition, enum member, const array, or built-in constant.

***

### GPC4015 — Recursive Combo Call

```
Combo '{name}' cannot call itself. Recursive combo calls are not allowed.
```

**Severity:** Error

A combo body uses `call({name})` on itself. Combos are state machines that each advance one step at the end of every `main` loop iteration; `call()` doesn't hand execution off to the other combo and move on — it pauses the calling combo's state machine until the called combo finishes running, then resumes where it left off. A combo calling itself would have to finish before it can finish, which can never happen, so the compiler rejects it outright. (Using `combo_run` on itself is merely useless — see GPC3008 — since `combo_run` starts a combo rather than pausing to wait for one.)

***

### GPC4016 — Mutual Combo Recursion

```
Combo '{name}' is part of a circular call chain: {A → B → A}. Mutual recursion between combos is not allowed.
```

**Severity:** Error

Two or more combos `call()` each other in a cycle (for example, A calls B and B calls A). Because `call()` pauses the calling combo's state machine until the called combo finishes, every combo in a cycle ends up waiting on another combo in that same cycle to finish first — none of them can ever complete. The message spells out the detected chain; break the cycle by restructuring so at least one combo in the chain no longer waits on a combo that, directly or indirectly, waits on it in return.

***

### GPC4017 — Empty Const Array

```
Const array must not be empty
Const array row {n} must not be empty
```

**Severity:** Error

A const array (or one row of a 2D const array) is declared with zero values. The array's size comes from its initializer, so an empty initializer is meaningless.

***

### GPC4018 — Invalid Const Array Structure

```
All rows must be the same size. Row {n} has {count} values, expected {expected}
```

**Severity:** Error

The rows of a 2D const array have different lengths. Every row must contain the same number of values as the first row.

```c
const int8 grid[][] = {
    { 1, 2, 3 },
    { 4, 5 }      // GPC4018 — expected 3 values
};
```

***

### GPC4019 — Invalid PS5ADT Data

```
PS5ADT data must have exactly 11 values, found {count}
```

**Severity:** Error

A `const ps5adt` entry does not contain exactly the 11 values the PS5 adaptive-trigger format requires.

***

### GPC4020 — Const Array Negative Index

```
Const array '{name}' accessed with negative index {index}
```

**Severity:** Error

A const array is indexed with a compile-time-constant negative value.

***

### GPC4021 — Const Array Index Out of Bounds

```
Const array '{name}' index {index} is out of bounds (size: {count})
```

**Severity:** Error

A const array is indexed with a compile-time constant that is `>=` the array's element count. Valid indexes are `0` through `size - 1`.

***

### GPC4022 — Variable Slot Underflow

```
Array access '{name}[{index}]' resolves to slot {slot}, which is below slot 0
```

**Severity:** Error

Non-const variable arrays are laid out as consecutive variable slots, and a constant index is resolved at compile time. Here the index is negative enough that the access lands *before* the first allocated slot — it would silently read or clobber memory outside the array.

***

### GPC4023 — Variable Slot Overflow

```
Array access '{name}[{index}]' resolves to slot {slot}, which is past the last allocated slot {last}
```

**Severity:** Error

Counterpart to GPC4022: a constant index on a variable array resolves past the end of all allocated variable slots.

***

### GPC4025 — Built-in Function Conflict

```
Function '{name}' conflicts with built-in function '{name}' and has different behavior
```

**Severity:** Error

A user-defined function is named after a pattern-detectable built-in (`min`, `max`, `clamp`) but its body does *not* implement the built-in's semantics. Because calls to these names bind to the built-in, keeping a different implementation would silently change behavior — rename the function.

This behavior check is special-cased to only `min`, `max`, and `clamp`. Naming a function after any other built-in (`set_val`, `get_val`, ...) is always a plain naming conflict — reported as GPC4001 — no matter what the function's body does.

***

### GPC4026 — Never-Ending do-while

```
Never-ending do-while loop: condition is always true and body has no break or return
```

**Severity:** Error

A `do { ... } while (condition);` whose condition is constant-true and whose body contains no `break` or `return`. On the Zen a script must yield back to the runtime every iteration of `main`; an infinite inner loop would hang the device, so it is rejected outright.

***

### GPC4027 — Never-Ending while

```
Never-ending while loop: condition is always true and body has no break or return
```

**Severity:** Error

Same as GPC4026 for `while (1) { ... }`-style loops with no exit.

```c
main {
    while (TRUE) {         // GPC4027 — no break/return in body
        set_val(PS4_CROSS, 100);
    }
}
```

***

### GPC4028 — Never-Ending for

```
Never-ending for loop: condition is always true and body has no break or return
```

**Severity:** Error

Same as GPC4026 for `for(;;)`-style loops (empty or constant-true condition) with no exit.

***

### GPC4029 — String Value in `define`

```
String literals are not allowed in define values
```

**Severity:** Error

A `define` is initialized with a string literal (e.g. `define NAME = "text";`). `define` values must be numeric compile-time constants.

***

### GPC4030 — Invalid `sizeof()` Operand

```
sizeof() requires a variable, array access, or type keyword
```

**Severity:** Error

The operand of `sizeof()` is not a variable, an array access, or a type keyword.

***

### GPC4031 — Const Array Single-Bracket 2D Access

```
Const array '{name}' is multi dimensional but is used as if it was single dimensional
```

**Severity:** Error

Single-bracket, value-context access to a two-dimensional const array (e.g. `M[i]` where `M` is declared `const T M[][] = {...}`). A 2D const array's element accessor takes a row **and** a column index — one bracket pair only supplies the row, so the access is rejected rather than silently reading an uninitialized column.

`image`, `string`, and `ps5adt` 2D arrays are exempt: they are row-addressed by design (a single bracket returns the row's base address, not a dereferenced row+column element), matching how the original Zen Studio compiler treats those two types. `addr(M[row])` is a separate, unaffected code path for any element type.

```c
const int8 M[][] = { {1, 2}, {3, 4} };
int x;
main {
    x = M[0];      // GPC4031 — M is 2D; write M[0][0] instead
}
```

***

### GPC4032 — Conditional Used as a Statement

```
Conditional expression result is not used
```

**Severity:** Error

A conditional expression is written as a bare statement instead of producing a value. The operator selects between two values; it is not a substitute for `if`/`else`.

```c
enabled ? set_val(PS5_CROSS, 100) : set_val(PS5_CROSS, 0);   // GPC4032

if(enabled) set_val(PS5_CROSS, 100);                         // OK
else set_val(PS5_CROSS, 0);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/troubleshooting/compiler-diagnostic-catalog/semantic-errors-gpc40xx.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
