0 votes

In the ready() method, I'm calling method on that is declared in the same script, _changestate(IDLE). The error is saying that my IDLE keyword in the call is out of scope, any ideas?

var state = null

func _ready():

func _change_state(new_state):
    emit_signal('state_changed', new_state)

    # Initialize the new state
    match new_state:

    state = new_state
Godot version v3.3stable.official
in Engine by (12 points)
edited by

which identifier? is the signal "state_changed" declared in this script or another?

Hello ener,

Thanks for your reply.

Yes! that method changestate() is declared on the same script file.

Also my apologies, I'll adjust the question.

The error is that in the line where changesate(IDLE) is being called. it is saying IDLE is out of scope. I'll edit the question.

1 Answer

+1 vote

the reason is you named your enum:

enum { A, B }
enum NAMED_ENUM { C, D }

func _ready():
    print(A) # ok
    print(NAMED_ENUM.C) # you have to do this explicitely
    print(C) # out of scope
by (728 points)

Hello Lola,

I see, Thank you for the answer. This worked the moment i updated it like that.

Do you know if there is a section in the documentation that talks about this so I can learn more on it, I haven't been able to find it. I come from programming in C++, C#, and Java, so not naming the enum is new to me.

Thanks again.

Sure! But as you can see there's not that much to it.
Unnamed enums are a shorthand to create a lot of constants.
Named enums in 3.x are dictionaries (no more in 4.0, they've removed the hack) meaning you can do this:

enum MyEnum { A, B, C }

func foo():
    for key in MyEnum:
        print("MyEnum.", key, " = ", MyEnum[key])

Which prints:

MyEnum.A = 0
MyEnum.B = 1
MyEnum.C = 2
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.