+7 votes

I created an enum with this code:

enum {
    IDLE,
    RUN,
    JUMP
}

And I'm trying to print the enums names instead of it's values for easily debug the game, is there a function for this? Thanks.

in Engine by (128 points)

1 Answer

+8 votes

According to this reddit post named enums act like dictionaries. So

enum_name.keys()[enum_name.WALK]

should work.

by (326 points)

Thanks. I have founded this post too but how could I print the enum from the example below? I have tried without success print("".keys()["".JUMP]) and print(keys()[JUMP]).

enum {
    IDLE,
    RUN,
    JUMP
}

I think that as of 3.1 you have to give the enum a name.

I'm using godot 3.3.4 and you can still use unnamed enums...

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.