Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow using print_line with enum #24

Open
coffandro opened this issue Feb 16, 2025 · 1 comment
Open

allow using print_line with enum #24

coffandro opened this issue Feb 16, 2025 · 1 comment

Comments

@coffandro
Copy link
Contributor

Currently when you print an enum (either just via print or Console.print_line) it prints the number that enum is, I think it'd be quite valuable to be able to make it automatically turn it back into the string type of the enum.

The method you need in godot 4.3 to get an enums string value is as follows

enum test {
    test1,
    test2,
    test3,
    test4
}

func get_test1():
    var variable = test.test1
    var variable_as_string = test.keys()[variable]

Sadly it dosen't seem possible to find the enum based upon the enum value, which we'd need to actually do this, I'm creating this issue in case there is a way to do so but I fear it isn't :/

@jitspoe
Copy link
Owner

jitspoe commented Feb 17, 2025

I did some tests, and it seems the type passed into a function when using an enum is considered to be an int, so there's no way to tell it's even an enum, let alone which enum in order to look up the name. I think you'll have to convert the enum to a name prior to calling the console print. You might be able to make a helper function like "Console.print_line(get_test_enum_name(test.test1))", but I don't think there's much that can be done beyond that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants