godot
godot copied to clipboard
GDScript 2.0: export_enum works only with int
Godot version
v4.0.dev.20211108.official [596865366]
System information
Windows 10
Issue description
In Godot 3 you could do this:
export(String, "Rebecca", "Mary", "Leah") var character_name = "Mary"
But if I try this in Godot 4:
@export_enum("Rebecca", "Mary", "Leah") var character_name = "Mary"
or
@export_enum("Rebecca", "Mary", "Leah") var character_name: String
It doesn't work and I get the error "@export_enum" annotation requieres a variable of type "int" but type "String" was given instead."
But according to the docs, it should be possible:
https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_exports.html
Steps to reproduce
Minimal reproduction project
No response
I'm new to the codebase so I might be wrong.
It seems like the part that responsible for annotations is not implemented for Godot 4.0 and the new @ export_enum
annotation.
Inside the export_annotaion
function you can see that there is no check for @ export_num
and writing @export_enum (" test1 "," test2 "," test3 ") var test: float
ignores the arguments and behaves like a normal export .
I think the way to fix this is to make some sort of a switch-case statement for each export annotation and to take care the behavior of each annotation.
also, let's not forget about this:
export(Array, String, "Rebecca", "Mary", "Leah") var character_names
if I understand correctly, the new syntax for that might look something like this:
enum CharacterNames {REBECCA = "Rebecca", MARY = "Mary", LEAH = "Leah"}
@export var character_names: Array[CharacterNames]
so the enum
keyword is missing support for string values as well. a separate issue?
also, let's not forget about this:
export(Array, String, "Rebecca", "Mary", "Leah") var character_names
if I understand correctly, the new syntax for that might look something like this:
enum CharacterNames {REBECCA = "Rebecca", MARY = "Mary", LEAH = "Leah"} @export var character_names: Array[CharacterNames]
so the
enum
keyword is missing support for string values as well. a separate issue?
Godot never had support for actual enums with string values. It only supports "fake" enums in exported properties (which are therefore not type-safe).
I didn't mean to suggest that it did.
this is about restoring the functionality for exporting arrays of string flags we had in Godot 3, and I assumed that enum
would be the way to do that since in Godot 4 named enums can be used as a type: Array[MyEnum]
, so apparently they are a little more than just Dictionary now.
according to the docs, @export_enum
is supposed to support both int and string values. if enum
had that same capability, then the Godot 3 feature set could be restored through that.
alternatively, I guess this would require a separate annotation like @export_enum_array
.
edit: btw this got its own issue reported here.
To add some context to this issue, the reason why exported enums with a string internal data structure are super useful is something like this simple example
As you can see here these are effectively a group of constants, the ability to have these saved as strings however avoids this issue here https://github.com/godotengine/godot/issues/56000 where changing whats in an enum (Pending where you change it) changes the index ordering of everything (Which I think everyone can agree is expected if you're using integers internally).
The only current workaround to the above I've found is to only add to the 'end' of the enum to prevent index changes, but if someone else knows a better way to accomplish this please do let me know!
don't we have any solution for this? I find it better than assigning integers
its on the docs but still returning errors. @export_enum("Wonderer", "Thrower", "Chaser") var enemyType: String = "Wonderer" @export_enum("Wonderer", "Thrower", "Chaser") var enemyType: String
@erniel: Likely docs not matching current state of engine. Unfortunately many docs weren't updated.
Also make triple sure that you're looking at latest, not stable docs
This was supported in godot 3... and now it's not... it's even in the docs. I think it's just not implemented yet.
Is there any update about this issue please?
Is it a documentation problem and we will not be able to use export_enum for String like it is written in the latest documentation? Is it a code problem? If so, is it aldready addressed and we should have a fix soon or not a priortity fix?
I am currently making some test to check the viability of using Godot Engine 4 for Tools development. I am new with Godot and it was for me the simplest and most intuitive way to create string combo list widget and be able to share it with multiple script.
Thank you for your time and keep the good work :)
EDIT: ok, just found the information about the priority level (Medium) in GDScript Stabilization Tasks page. I will check the release notes of new Godot beta version :)