|
|
|
|
Reply From: |
sash-rc |
- You can use C++ enums in C++ part without any limitations
- Godot’s enums aren’t actually a type, but like a set of const literals.
- If you want to pass it in and out of Godot, use
int
For a nice property in inspector, you could use
enum MyEnum { E1 = 0, E2, E3};
// CClass
MyEnum myEnum;
void setEnum(int newValue) { myEnum = (MyEnum) newValue; }
int getEnum() { return (int) myEnum; }
register_property<CClass, int>("MyEnum", &CClass::setEnum, &CClass::getEnum, (int) E1,
GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT,
GODOT_PROPERTY_HINT_ENUM, "E1, E2, E3");
When I want to register the property
in .h
public:
enum MyEnum { E1 = 0, E2, E3};
MyEnum myEnum;
void setEnum(MyEnum newValue) { myEnum = newValue; }
int getEnum() { return myEnum; }
in .cpp when registering the property
register_property<PruebaEnumeracion, int>(
"MyEnum",
&PruebaEnumeracion::setEnum,
&PruebaEnumeracion::getEnum,
E1,
GODOT_METHOD_RPC_MODE_DISABLED,
GODOT_PROPERTY_USAGE_DEFAULT,
GODOT_PROPERTY_HINT_ENUM,
"E1, E2, E3"
);
There is an error and it says this I don’t understand why it
no instance of overloaded function "godot::register_property" matches the argument list -- argument types are: (const char [7], void (godot::PruebaEnumeracion::*)(godot::PruebaEnumeracion::MyEnum newValue), int (godot::PruebaEnumeracion::*)(), godot::PruebaEnumeracion::MyEnum, godot_method_rpc_mode, godot_property_usage_flags, godot_property_hint, const char [11])C/C++(304)
register_property
I imagine that there must be problems on many sides if we use the enum as the data type, in my case the problem was a parameter with the data type that is enum
There was an typo (fixed): of course you need to cast enum
to int
and vice versa: data types of setter/getter should match declaration in register_property
sash-rc | 2021-09-02 19:53