Could someone explain to be where / when an enum is usefull? From what understand, you could just use a string instead. For example:
this:
extends Node2D
class_name Card2D
# //types: sun, moon, sword, sheild
enum suits {
SUN,
MOON,
SWORD,
SHEILD
}
@export var suit = suits
func _ready():
if suit == suits.SWORD:
$Sprite.Texture = "res://sword.png"
elif suit == suits.SHEILD:
etc...
can also be writen as:
extends Node2D
class_name Card2D
# //types: sun, moon, sword, sheild
@export var suit: string
func _ready():
if suit == 'sword':
$Sprite.Texture = "res://sword.png"
elif suit == 'sheild':
etc...
because in both examples, if I want to change "sun"/suits.SUN to "star"/suits.STAR, I still need to go through all occurences of it in my code.
Whats the point of using it?
The only benifit I see is that you have a dropdown in the inspector instead of typing out the string. Could someone pls enlighten me?
thanks!!