How to register_property of string type in gdnative c++ with selecting value from an array of strings options?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robotex

In gdscript you can do it by export param:

export (String, “Rebecca”, “Mary”, “Leah”) var character_name

How to do it in c++ gdnative? Is it possible to select value not from constant list of strings but from dynamic array of strings?

:bust_in_silhouette: Reply From: cm

With latest (currently 4.0 alpha 7) you can export a choice of strings by using PROPERTY_HINT_ENUM:

ADD_PROPERTY(PropertyInfo(Variant::STRING, "character_name", godot::PROPERTY_HINT_ENUM, "Mary,Rebecca,Leah"), "set_character_name", "get_character_name");

Concerning the second part, I don’t believe that modifying the choice list is currently possible with extensions - only with module development. The reason is that Object::_validate_property is not available to extensions. See this discussion

Will it work with 3.x? I need to collect all available input commands and then select from that array with dropbox.

Robotex | 2022-05-11 19:49

It doesn’t seem that exporting enums is possible in 3.x. See this discussion.

You might be better off creating a string parameter in GDNative and building a wrapper in GDScript to provide an enum. Though that doesn’t help with dynamically populating items.

For dynamic population I think you’re limited to writing a proper module for now. Check out the source for AudioStreamPlayer, which modifies it’s bus enum parameter when an audio bus is added or removed.

cm | 2022-05-11 20:14