17.6 C
New York
Monday, April 28, 2025

godot – How to fix “Identifier not declared in current scope” error?


“Line 45” tells you that the problem is on line 45:

t_bob += delta * velocity.length() * float(is_on_floor())

You mean a variable called delta here (that’s the “identifier”), but there is no variable defined with that name anywhere inside this function (the “current scope”).

There is one declared as an entry in the _physics_process(delta) function, which represents the duration of simulation time since the last physics update. However, we can’t access that from line 45, because it’s a completely different function executed at a different time.

It looks like you should move this move code to _physics_process so it is called once per physical tick, not once per input. That will be the general rule for code that depends on being called at regular time intervals measured by the delta variable.

I recommend reviewing your fundamentals on variable scopes and others GDScript basics so you can read, understand and fix these types of common error messages without help.

Questions about general programming concepts like this that are not unique to games can be closed and redirected to StackOverflow, which already has a lot of Questions and answers explaining variable scopes in Godot.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles