i want an export variable whose values default to the values of an enum. But i don’t know an easy/elegant way to turn the list of enum values into an array to use as the default value. The code:
Purpose: Most towers can use all 10 targeting strategies but a few can’t. Rather than make them enter which enum values are allowed (since it’s normally all of them), i want to start them with the list and let the exception cases delete values.
In Java or Kotlin i could do something like allowed_targeting = TargetingStrategy.map{it.name}. Something with a loop. i don’t know how to loop over an enum in GDScript.
i could do that but it’s a lot of typing (i suppose 10 isn’t a lot but it feels like it) and more importantly as i add new enum values i have to keep both lists in sync. If there’s no programmatic way to do it then i’ll have to resort to hard coding it but before i do i want to see if there’s a more maintainable way.
Also, here u can see how to iterate over the enum with the map method or u could also do it with a for loop, since that by the end of the day, enums are dictionaries.
i like the code but the problem is that @export variables behave a little weirdly. i have to initialize the values in the declaration line, can’t do it in _ready(). If this weren’t an export variable this would be a lot easier.
After playing around with a couple of options i think i’ll bite the bullet and just manually specify the values and accept the maintenance burden.