Identifier "CommandDispatcher" not declared in the current scope.

Godot Version

4.6.1

I created a script where I declared several signals and in another script I am trying to refer to that script to use the signals and am getting the error “Identifier “CommandDispatcher” not declared in the current scope.” What am I doing wrong? I’m following a tutorial step-by-step and the guide had no issues when they did it this way.

There should be

class_name CommandDispatcher

at the beginning of your CommandDispatcher.gd script.

That seems to have changed the error but now I’m getting

“Cannot find member “PROCESS_COMMAND” in base “CommandDispatcher”.

I see, then probably what you want is an autoload, not a class. In this case forget what I mentioned and read through this article:

2 Likes

This solved it!

Would you mind explaining why simply having it as a class wouldn’t work? If not that’s ok, I’m just still learning.

If @wchc 's post solved the problem, then click that solved button on that post.It helps other people to find the solve easily

3 Likes

When you have defined a class CommandDispatcher and then you write CommandDispatcher.PROCESS_COMMAND, you request a static property of the class. We don’t have static signals in GDScript currently (see proposal #6851), that’s why it fails.

When you define an autoload, it’s a bit special case which looks the same as if it were declared as a class, but it’s actually an instance that you can refer to as CommandDispatcher. Then when you write CommandDispatcher.PROCESS_COMMAND, you request a property of the instance, a signal in this case, which is perfectly valid.

4 Likes

Thank you! This is very helpful. I appreciate you taking the time to educate me.

1 Like