godotengine / godotengine/godot-docs
Exporting bit flags section confusing
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
**Your Godot version:**
v4.2.1.stable.mono.official [b09f793f5]
**Issue description:**
I have a C# enum and I'm trying to enable using it as a bitset, where some Node script can have 0 or more values of this enum set. I'm aiming to avoid having to fiddle around with ints if possible.
The first point of confusion comes from the first code snippet, which contains this at the end:
```csharp
[Export]
public SpellElements MySpellElements { get; set; }
```
This...doesn't appear to work or do anything. `SpellElements` isn't defined as a type anywhere else in the document.
Secondly, with this block:
```csharp
// Set any of the given flags from the editor.
[Export(PropertyHint.Flags, "Fire,Water,Earth,Wind")]
public int SpellElements { get; set; } = 0;
```
it's unclear how this variable's declaration is connected with the enum created earlier. Probably because...it's not! Right? The flags in this type are duplicated by the enum and happen to be in the same order, which is required for it to "work".
Lastly, there's no explanation of how to use the flags. The section feels a bit incomplete, kind of "and then what?" I believe I need to use bit manipulation here? Something like `((MyEnum)SpellElements).HasFlag(MyEnum.Fire)`? I'm not even sure I can cast an int to an enum, I'm just kinda guessing.
There's also this in the same section:
```csharp
[Export(PropertyHint.Layers2DPhysics)]
public uint Layers2DPhysics { get; set; }
```
which doesn't seem relevant to bit flags, even if they're technically implemented as bit flags.
**URL to the documentation page:**
https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/c_sharp_exports.html#exporting-bit-flags
If you know how to fix the issue you are reporting please
consider opening a pull request. We provide a tutorial on
using git here: https://docs.godotengine.org/en/stable/community/contributing/pr_workflow.html,
writing documentation at https://docs.godotengine.org/en/stable/community/contributing/docs_writing_guidelines.html
and contributing to the class reference here: https://docs.godotengine.org/en/stable/community/contributing/updating_the_class_reference.html
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.