Godot: export(enum) saves values and not identifiers

Created on 8 Feb 2018  路  4Comments  路  Source: godotengine/godot

Godot version: 3

Issue description:
This is a suggestion on how exported enums should be saved. Currently, values are saved instead of the identifier. For example:

enum ENUM {A, B, C}
export(ENUM) var value

Choosing B in the editor will save the line value = 1 in the .tscn file. I would expect B to be saved instead, since changing the enum could very easily and, more importantly, silently break settings.

discussion enhancement gdscript

Most helpful comment

If there is a mistake in the enum or you need to change an identifier for some reason, then you need to refactor all the code that uses the name anyways, so modifying the exported variables is no big deal compared to that.

Writing enum ENUM {A=1, B=2, C=3} doesn't really solve the issue. What if you want to insert FIRST_CHAR = 1 in front of the array for some reason, then this does not break any code, but all exported variables get shifted. This is what I mean by silently breaking settings. I'd rather get errors when modifying the enum than seeing nothing and having to track bugs because of this.

Plus it makes more sense to save the identifier, the entire point of an enum is to hide the value behind a human readable identifier.

All 4 comments

Hi.

I think it is clever to save the value of the enum instead of the identifier.

For Example:

enum ENUM {Alpa, Beta, Charlie}

If Godot would store Alpa instead of 0 and you correct the misspelling and change Alpa to Alpha the settings would be broken. That means that you never could change the identifier of any enum once you used it in the editor!

Anyways, you can always declare your enums like this:
enum ENUM {A=1, B=2, C=3}
If you do it this way, you are always on the save side.

If there is a mistake in the enum or you need to change an identifier for some reason, then you need to refactor all the code that uses the name anyways, so modifying the exported variables is no big deal compared to that.

Writing enum ENUM {A=1, B=2, C=3} doesn't really solve the issue. What if you want to insert FIRST_CHAR = 1 in front of the array for some reason, then this does not break any code, but all exported variables get shifted. This is what I mean by silently breaking settings. I'd rather get errors when modifying the enum than seeing nothing and having to track bugs because of this.

Plus it makes more sense to save the identifier, the entire point of an enum is to hide the value behind a human readable identifier.

I think it should store Value and Identifier both as in C#, well that's what I love about Enums no need for dictionaries. They are Better dictionaries for basic use.

I think this is related:

Let's say you have a tile based game and you assign each object a tile in the Inspector.

  • EnemyTriangleTile, PlayerTile, NeutralBlockTile
    They will be assigned 0 - 1 - 2 and stored in the meta file
    If you add a new enemy between EnemyTriangleTile and PlayerTile the assigned tiles in the level will get moved by 1 if they come after the newly added tile which is insanely annoying because you have to reassign them in all of your scenes.

"But you can just add them to the end":

  • Yes but I have a lot of tiles and would like to order them by category to be able to find them quicker.
  • I think storing the identifier makes much more sense for cases like mine

Note: I'm currently using C# but it's basically the same problem

Was this page helpful?
0 / 5 - 0 ratings