Godot Version
godot-4
Question
I am trying to use enum as Configuration key and I want to store the matching value into a Dictionary. A key-value store of configurations, with static names.
The problem I am facing is that the parser complains the format of the key.
res://Game/Singletons/UIConfiguration.gd:11 - Parse Error: Expected identifier or string as Lua-style dictionary key (e.g “{ key = value }”).
(line 11 is the first initialization)
extends Node
class_name UIConfiguration
enum ConfigurationKey {
Progress_bar_height,
Progress_bar_width
}
var _IntConfigurationValues : Dictionary[ConfigurationKey, int] = {
ConfigurationKey.Progress_bar_height = 48,
ConfigurationKey.ConfigurationKey.Progress_bar_width = 320
}
If is use another form
var _IntConfigurationValues : Dictionary[ConfigurationKey, int] = {
Progress_bar_height = 48,
ConfigurationKey.Progress_bar_width = 320
}
Then I face the runtime error:
E 0:00:00:217 UIConfiguration.gd:10 @ @implicit_new(): Unable to convert key from “StringName” to “int”.
<C++ Error> Method/function failed.
<C++ Source> core/variant/dictionary.cpp:478 @ assign()
UIConfiguration.gd:10 @ @implicit_new()
Question
what is the correct form to initialise with Enum?