Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDScript 2.0: Named Enums cannot be set to use Flags when exported #71234

Closed
sp3llwe4ver opened this issue Jan 11, 2023 · 3 comments
Closed

GDScript 2.0: Named Enums cannot be set to use Flags when exported #71234

sp3llwe4ver opened this issue Jan 11, 2023 · 3 comments

Comments

@sp3llwe4ver
Copy link

sp3llwe4ver commented Jan 11, 2023

Godot version

Godot 4.0 beta 11 x64 Windows

System information

Windows 11

Issue description

When exporting named enums in 3.5.x you could define them outside of the export declaration and then export them with flags. The enum could be defined within the file you were working on, or in an autoload file.

For example, this works in 3.5

Enum defined in an autoload file named Types:

enum ColorTypes{
HUMANSKIN,
HUMANHAIR,
RED,
BLUE,
YELLOW,
GREEN,
VIOLET,
ORANGE,
REDORANGE,
YELLOWORANGE,
YELLOWGREEN,
BLUEGREEN,
BLUEVIOLET,
REDVIOLET,
BROWN,
GREY,
BLACK,
WHITE}


extends Resource

class_name DefinedColor

export (Types.ColorTypes, FLAGS) var colorType

export (Types.ColorValue) var colorValue

export (String) var name

export (Color) var vColor

tldr for character generation I want to create predefined colors, and then flag them with what category they fall in, and whether the naturally occur as a hair or skin color. I'd also want to do this for other named enums as well.
And this works well in 3.5.x- when defining a export var using a named enum there are checkboxes available I can use to set the var up in editor where in a node or custom resource. However in 4.0 beta that no longer seems to be the case

As shown in the documents, we can do this for enums if we define them during the export
@export_flags("Fire", "Water", "Earth", "Wind") var spell_elements = 0

We should have the same functionality for Named Enums in 4.x

My attempt at implementing in Godot 4.0 beta 11 in my project, to be clear not messing with the editor's code, just playing around to see if the functionality is there:


class_name DefinedColor 
#The following two ways I tried don't work and I wasn't able to find how to do it in the documentation so I believe this is missing functionality

@export_flags(Types.ColorTypes) var colorType

@export(Types.ColorTypes, FLAGS) var colorType2

@export var colorValue: Types.ColorValue

@export var name: String@export var vColor: Color

Steps to reproduce

  1. Create a new Godot project
  2. Create a new script extending resource or node
  3. Create a named enum with multiple options
  4. Attempt to create an exported variable using the previously created named enum with flags

Minimal reproduction project

N/A

@rosshadden
Copy link
Contributor

Is there a workaround for this until it's added? I used to rely on this in Godot 3.x. I guess our best bet for now is probably just hardcoding 😷 the bit flags 🤢 for now 🤮.

@dalexeev
Copy link
Member

dalexeev commented Feb 15, 2023

I think it should be implemented as a separate annotation:

@export_flags_enum(named_enum: Dictionary, values_as_bits: bool)
enum Enum1 {A, B, C, D} # 0, 1, 2, 3
enum Enum2 {A = 1, B = 2, C = 4, D = 8}

@export_flags_enum(Enum1, true) var var1: int
@export_flags_enum(Enum2, false) var var2: int

EDIT. Since there is no similar annotation for using enum on a non-enum-typed variable, I'm now not sure if a similar annotation for flags is a good idea.

@YuriSizov
Copy link
Contributor

YuriSizov commented Feb 15, 2023

Or we can have an annotation for the enum declaration itself to make it auto-assign values using power of 2 instead of linearly? Because that would make those enums useful for scripting in general, not just in the export notation.

Either way, this is a proposal material, so it should be argued as a feature proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants