These days enum values require to be prepended with the name of enum, like this:
TileType.TileType.SOLID
Thank you, that worked for me.
I suppose this makes sense as I’m loading in a class with an enum inside it, but it still feels bloated. Is there a way to use the syntax “Enum.Value” in multiple scripts?
Ben Humphries | 2020-06-02 10:14
I don’t think it’s possible. What you can do is not use an enum but a couple of constants:
const EMPTY = 0
const SOLID = 1
As a bonus you won’t be able to accidentally delete these constants. Sadly, enum’s contents can be deleted.
I run into this behaviour when autoloading a script file that contains an enum. To fix this behaviour i usually assign each enum value an index number, so it would be:
I had the same issue. For me, the actual problem was preloading - in an autoload script - a script which referenced another autoload script. See the following simplified example of the problem and then the solution afterward.
Autoscripts (in order) Config.gd
enum TILE_TYPE {NONE, FLOOR, WALL}
Global.gd
var Tile = preload("res://Tile.tscn") # <-- This caused the error
var tile = Tile.instance()
# do stuff with tile
Non-Autoscripts Tile.gd
export(Config.TILE_TYPE) var type = Config.TILE_TYPE.NONE
By removing the preload of Tile.tscn from Global.gd, the error went away. For me, this is an acceptable solution because I’m realizing in hindsight that instancing Tiles elsewhere is more appropriate.
I also verified that referencing enums in Config.gd from within Global.gd works. E.g.
If you need to preload - in an autoload script - a scene which references enums in another autoload script, similar to what I was doing in Global.gd, then you need to preload the autoload script similar to one of the following examples, depending on your use case.
Tile.gd
export (preload("res://Game/Config.gd").TILE_TYPE) var type
OR
const TileTypes = preload("res://Game/Config.gd").TILE_TYPE