[QUESTION] flag-like enums

Started by eri0o, Mon 16/12/2024 16:37:33

Previous topic - Next topic

eri0o

Some enums support being used like flags - meaning you can do bitwise boolean "or" operations to them to use as input in some functions. Currently in the engine there is InputType and RenderLayer - there may be other recent ones I am forgetting.

The issue is there is no symbol/keyword that gives some "contractual" awareness they can be used in this way.

I would like to suggest we use f instead of e as the preceding letter, to indicate these are flags.

I don't know if there's something else that can be done here though, so I thought I should ask. I will probably also add some "standard" way to tell this in the Standard Emums section of the manual.

Crimson Wizard

#1
There are more enums that are defined like flags:
- Alignment (although they are not necessarily used like flags right now),
- eFlipDirection (has flag-suitable values either by intent or by accident),
- eKeyMod (since 3.6.0),
- InputType (since 3.6.0).

The new ones in 3.6.2:
- RenderLayer,
- RestoredSaveResult
- SaveComponentSelection,

in AGS 4:
- StringSplitOptions,

While I am not entirely against the idea of a prefix itself, changing all of them consistently will break scripts that use these enums, and will require users to change their typing habits, which may be more damage than advantage gain from this change.

eri0o

Most of these are new - except flip and alignment - so I don't think that is that big an issue.

But for other options, C# has a flags attribute it can use to signal this in the enum definition.

I guess for now I will just figure a way to document it as a note in the standard enums docs page in the mentioned new ones and maybe add a text somewhere that explains what is "flag behavior" or something like this.

Crimson Wizard

Quote from: eri0o on Mon 16/12/2024 17:22:50Most of these are new - except flip and alignment - so I don't think that is that big an issue.

So you want to rename only newer ones?

Is this suggested for ags3 or ags4?

eri0o

No, first I would like some input if my train of thought makes sense or not.

It can be a bad idea too, as you said people may just be used to typing "eWhatever" as a way to list enums in the script editor.

It's just something that as I was writing the docs I noticed that I didn't knew much how to signal this property that these specific enums have that they can also be combined.

Crimson Wizard

Hmm, supposing the second mentioned alternative, if we have a sort of "decorator" or a keyword to mark the "flag enums", how would that affect the situation?
Would that be used in autocomplete hints?

eri0o

It could in some way, although idnk how, and could also show in the call tip. I mostly just wanted to note this somewhere as this has been on my mind since I thought about the writing of docs of 3.6.2.

cat

I think the f prefix will cause more confusing than clarity.

SMF spam blocked by CleanTalk