"Cannot get property from enum value"

Godot Version

Version 4.4.1

Question

In the game I’m working on I have it where I need to make a custom button to go along with a custom Cursor. I thought using Enums would be a good way to determine what type of button it is. but I ran into a problem trying to to check which enum the variable that stored it in was…

Here’s the snippet of the code that should be contributing to the error:

enum ButtonTypes {NextCam, PrevousCam, Other}
@export var ButtonType: ButtonTypes = ButtonTypes.Other

func CheckClick():
	if has_overlapping_bodies() and Input.is_action_just_pressed("MouseL"):
		if ButtonType == ButtonType.NextCam: #This line has the error "Cannot get property from enum value"
			pass #What ever that button type does, Haven't gotten there yet.

I am fairly new with coding with Godot so there easily could be some easier way around this.
This is the first time I’ve encountered an error and not able to find the answer online.
Thanks to anyone that knows.

you have ButtonType.NextCam instead of ButtonTypes.NextCam this is the bug.

Also, I recommend GDScript style guide and use different variable names to you, for example:

enum ButtonTypes {NEXT_CAM, PREVOUS_CAM, OTHER}

@export var button_type: ButtonTypes = ButtonTypes.OTHER

func CheckClick():
	if has_overlapping_bodies() and Input.is_action_just_pressed("MouseL"):
		if button_type == ButtonTypes.NEXT_CAM:
			pass
2 Likes

Thank you so much!
Thanks also for the reminder about the style guide, I should look at that again