I need help with enum value checking

Godot Version

4.3 (Newest)

Question

I wanted to make variations for fruits using enum. But doing the check with “if” (meaning this: if fruit_skin_type.APPLE:
sprite.play(“IdleApple”))
There seem to be no errors, but there is no check (I wrote “print(helo)” to check if it works).
Can anyone please help? Thanks in advance!
Here’s the code:


enum fruit_skin_type {APPLE, BANANAS, CHERRIES, KIWWWI, MELON, ORANGE, PINEAPPLE, STRAWBERRY}
@export var fruit_skin : fruit_skin_type

@onready var sprite: AnimatedSprite2D = $Sprite

func _process(delta: float) -> void:
	if fruit_skin_type.APPLE:
		sprite.play("IdleApple")
	if fruit_skin_type.BANANAS:
		sprite.play("IdleBananas")

Or screenshot:

You’re not using the fruit_skin variable in your if-statements. What you want to write is this:

	if fruit_skin == fruit_skin_type.APPLE:
		sprite.play("IdleApple")
	if fruit_skin == fruit_skin_type.BANANAS:
		sprite.play("IdleBananas")
# ...and so forth

Your current code is the same as writing (see docs):

	if 0:
		sprite.play("IdleApple")
	if 1:
		sprite.play("IdleBananas")
1 Like

Thank you! Everything is now being checked calmly. Thank you very much again!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.