#Defining an exported dictionary keys with a list of possible keys, set in advance.

1 messages · Page 1 of 1 (latest)

hoary ibex
#

Hello, is it possible to define **keys **as string, in an **exported dictionary that would have **float **values, with ONLY a specific list of possible keys ?
Only way I found was to make an enum with the names of my keys, but when calling this dictionary I then need to call the keys as integers.

I can accommodate myself from this if needed but it'd be easier to manage code with strings since it's to define some properties on a reccuring object in my games (spells, in this screen).

In the second screen, you can see a solution, however it does not have set number of possible keys, which is makes it prone to error when defining a new object. I might go with this without a better solution.

Finally, I'd like to avoid using the Tool function (because I'm pretty sure it can be done with the tool function) ; I did it in the past and found that I'm not competent enough to not make crash my pc with it every once in a while 👀

Thanks to anyone passing for your time and help !

tribal verge
#

Re: enums: enums are themselves dicts of stringname->integer, so you can use get or [] on strings to get the numbers (or ofc the defined constants in the enum)

#

So it's one more lookup, but at least your code wouldn't be littered with opaque magic numbers

hoary ibex
#

Oh is it that simple ?

#

Great

#

So altought it's a bit more wordly, I can do this ?

#

(Just ran it and it technically works)

#

Waiting a bit to put the solved tag for any other suggestion if anyone as one, but considering it solved still

tribal verge
#

This feels like it's not using enums the way id think

#

I think you have a dict SomeEnum->float, which is tokens, right?

#

Or I guess available_tokens?

#

So it would be spell_resource_data.available_tokens[SomeEnum.pierce] iiuc