Skip to content

BIND_ENUM_CONSTANT Behavior in GDSScript #1998

@silenuz

Description

@silenuz

Godot version

4.6.1

godot-cpp version

4.4 (using the template)

System information

Linux

Issue description

Not sure if this is a bug or intended behavior or me just being confused.

So I'm using the TrafficLight example from Godotcon 2024. I was adding some signals to parse and couldn't figure out how to access the enumerator values from GDScript. The original implementation seems to lead to
enumerator value names being incomplete-able because the enumerator value names include a double colon.

Below is full account.

Steps to reproduce

Given the original code to register the enumerator values:

BIND_ENUM_CONSTANT(TrafficLightType::TRAFFIC_LIGHT_GO)
BIND_ENUM_CONSTANT(TrafficLightType::TRAFFIC_LIGHT_CAUTION)
BIND_ENUM_CONSTANT(TrafficLightType::TRAFFIC_LIGHT_STOP)

Results in enumerator value names that are incomplete-able in GDScript as the name is the qualified name and not the enumerator's value name.

Image

Which leads to something like this failing

Image

with SCRIPT ERROR: Parse Error: Cannot find member "TRAFFIC_LIGHT_CAUTION" in base "TrafficLight.TrafficLightType".

If I register each as a separate integer constant like this:

ClassDB::bind_integer_constant("TrafficLight","TrafficLightType","TRAFFIC_LIGHT_GO",TrafficLightType::TRAFFIC_LIGHT_GO);	ClassDB::bind_integer_constant("TrafficLight","TrafficLightType","TRAFFIC_LIGHT_CAUTION",TrafficLightType::TRAFFIC_LIGHT_CAUTION);	ClassDB::bind_integer_constant("TrafficLight","TrafficLightType","TRAFFIC_LIGHT_STOP",TrafficLightType::TRAFFIC_LIGHT_STOP);

Then it almost works but the enumerator values end up bound "twice" so to speak. They end accessible as a constant in TrafficLight:

Image

And as an enumerator value:

Image

I assume this is because the enumerator is part of the class declaration and as such each enum value is local? Is this how the BIND_ENUM_CONSTANT macro is supposed to work with the colons in the name enum variable name? Shouldn't it work almost like the individual registering of each enumerator value name?

In case it helps here's the xml doctool spits out in each case, original first:

<constants>
    <constant name="TrafficLightType::TRAFFIC_LIGHT_GO" value="0" enum="TrafficLightType">
    </constant>
    <constant name="TrafficLightType::TRAFFIC_LIGHT_CAUTION" value="500" enum="TrafficLightType">
    </constant>
    <constant name="TrafficLightType::TRAFFIC_LIGHT_STOP" value="501" enum="TrafficLightType">
    </constant>
</constants>

Individual Register:

<constants>
    <constant name="TRAFFIC_LIGHT_GO" value="0" enum="TrafficLightType">
    </constant>
    <constant name="TRAFFIC_LIGHT_CAUTION" value="500" enum="TrafficLightType">
    </constant>
    <constant name="TRAFFIC_LIGHT_STOP" value="501" enum="TrafficLightType">
    </constant>
</constants>

Minimal reproduction project

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions