not sure what unexpected identifier is

Godot Version

4.3

Question

`what is a identifier? i am not sure how to debug this strip of code:

$TwistPivot.rotate_y(twist_imput)
$TwistPivot/PitchPivot.rotate.x(pitch_input)
$TwistPivot/PitchPivot.rotation.x = clamp(
$TwistPivot/PitchPivot.rotation.x,
-0.5,
0.5
)
twist_input = 0.0
pitch_input = 0.0

error line is:
"twist_input = 0.0

it says unexpected identifier but i am not sure what this is or how to solve

thanks`

Is that code inside a function?

twist_input = 0.0 needs to be inside a function:

func something():
    twist_input = 0.0

Godot doesn’t know what to do with executable code that isn’t in a function.

You havent declared the variable twist_input. Try:

var twist_input = 0.0

Also the same for pitch_input

I don’t think “Unexpected Identifier” means it’s undefined, I think it means the parser found an identifier in a place it didn’t expect to find an identifier.

If it was just undefined, the error message is Identifier twist_input not declared in the current scope.

2 Likes

Which is equivalent to undefined. Definition is always scope dependent.

Sure, but the reported error is “unexpected identifier”, not “undefined” or “not declared”.

That’s what they choose to call it. The error is: “the known name (identifier) is expected here, but the name (identifier) you provided is unknown in this context/scope and therefore not expected”

The point is: What they choose to call it is “unexpected identifier”, and that error in Godot is a result of the parser finding an identifier where it wasn’t expected, not a result of Godot finding an unknown identifier. Godot has a different error message for unknown identifiers.

The OP said “unexpected identifier”, and that, in Godot’s error reporting, tends to be an identifier in an unexpected place, like (say) outside of a function, without a var prefix. Or on the same line as another statement without a separator.

3 Likes

You’re right, it’s reserved for identifiers that appear in class declarations. Within functions it’s “identifier not declared”, although it’s basically the same error. Well not exactly the same because you can’t write expressions in class definitions, hence any identifier is not expected there even if it has been declared. I stand corrected.

Typo.

The good variable name is twist_imput with an “m.” The second, where the error is generated, uses an “n.”

1 Like