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

Display enum name next to its value in the Remote Inspector #255

Open
PLyczkowski opened this issue Nov 24, 2019 · 8 comments
Open

Display enum name next to its value in the Remote Inspector #255

PLyczkowski opened this issue Nov 24, 2019 · 8 comments

Comments

@PLyczkowski
Copy link

Describe the problem or limitation you are having in your project:

During debugging, it's slow to have to check what the value of an enum means in my code by searching for the enum declaration.

Describe how this feature / enhancement will help you overcome this problem or limitation:

This feature would tell me instantly what a value of an enum means.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:

Untitled-2

If this enhancement will not be used often, can it be worked around with a few lines of script?:

Not really, it's low level editor code I'm guessing.

Is there a reason why this should be core and not an add-on in the asset library?:

There are now drawback to this being core as far as I can see.

@nobuyukinyuu
Copy link

I'm guessing this applies to the remote inspector; in the local one you can set an export type to either a built-in or named enum and get this capability. In that case, the value is masked and the name is used in the inspector. In that instance, Showing only the name of an enum value and not the value itself is not usually an issue as the labels often exist not just for syntactic convenience but also to help future-proof code.

@Calinou Calinou changed the title Display enum name next to it's value in the Inspector Display enum name next to its value in the Inspector May 4, 2020
@Calinou Calinou changed the title Display enum name next to its value in the Inspector Display enum name next to its value in the Remote Inspector Jun 19, 2020
@frozenMustelid
Copy link

/signed

I'm starting to think that the person who added enums to Godot doesn't even understand why programmers like the concept of enums. They seem so broken and there isn't a fully satisfactory workaround for their jank. Having to declare every enumerated value's name again every time you export a var that uses that enum is ridiculous.

@Calinou
Copy link
Member

Calinou commented Oct 30, 2020

@frozenMustelid Nobody contributes to Godot specifically to annoy others 🙂

I have to remind you that we have a Code of Conduct. Please stay constructive.

@ian-p-mcpherson
Copy link

I'm running into this inconvenience also. I wouldn't call it an issue but it's a feature I'd really like to see so I don't have to make my own debugger in cases where I have dictionaries of enums that are time consuming to decipher.

@cyda89
Copy link

cyda89 commented Oct 11, 2024

I'll join in here - it would be very helpful to be able to find out the name for enum values in a simple way. Not only specifically in the remote inspector, but generally. Another use case:

  1. Your game has many different types that are represented by enums.
  2. All types are summarized in a script Types.gd to make them easily accessible.
  3. Now you want to have a function in Types.gd that returns the name of the the values of any of your enums (e.g. for logging or use in the ui). There is currently no way (that i could figure out) to do this other than writing a separate function for each individual type like
func e_name(key: int) -> String:
    return MyEnum.keys()[key]

Perhaps part of the solution to the above problem could be a revision of the enums to allow such functionality, or at least derive the name of an enum from the type (e.g. MyEnum.toString() -> “MyEnum” or something).

@PLyczkowski
Copy link
Author

PLyczkowski commented Oct 11, 2024

@cyda89

func enum_to_enum_name(enum_dict:Dictionary, enum_int:int) -> String:
	var enum_name : String = ""
	var keys : Array = enum_dict.keys()
	for key in keys:
		if enum_dict[key] == enum_int:
			enum_name = key
			break
	return enum_name.capitalize()

(I wrote it a long time ago, I don't think it needs a for loop in it)

@cyda89
Copy link

cyda89 commented Oct 11, 2024

Thanks @PLyczkowski for your answer. It helped me a lot to develop an even more generic solution where I assign universally unique integers to every value and then use this function:

func e_name(key: int) -> String:
	var all_enums: Array[Dictionary] = [MyType, MyOtherType, MyNewType]
	var result: String
	
	for dict in all_enums:
		for name in dict.keys():
			if dict[name] == key:
				result = name
				break

	return result

Could probably be tweak concerning efficiency, but since the enums never contain more then 6-7 values, I don't care too much.

@thiscris
Copy link

Hey, I just noticed that the regular inspector displays enum names, when you hover over an exported variable.

On the other hand the remote inspector doesn't show descriptions, regardless of the variable type
( I opened a bug about it at godotengine/godot#101871 )

A workaround is that you can add @export to the variable and during debugging, scroll down to the script parameters (below the members section)

Image

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

No branches or pull requests

7 participants