Managing keys/strings?

Godot Version

4.0

Some info’

Hello!
I am working on adding a variety of effects to my game, but I’m not sure how to manage them.
In my project, I have two places (resources) that have dictionaries, like this:

var example_dictionary: Dictionary = {
	
	"GROUP_A": {
		"A1": {
			"info": {"effects": ["effect_1", "effect_2"], ...},
			"visuals": {...}
			},
		
		"A2": {
			"info": {"effects": ["effect_5"], ...}, 
			"visuals": {...}
			},
	},

As you can see, the effects are stored in a list, as strings.

The Problem

Because the effect keys are strings, if I want to add an effect to something, I have to look through my “effects list” to find the correct key, (or somehow remember them all,) so I can type it correctly into the list. This problem also occurs when I’m implementing said effects, because I have to use the correct effect-strings in if- and match statements. (And also, what if I decide to change the name of an effect, then I’ll have to update it everywhere… Manually!)

The Question

Is there a way to create something to store keys/strings so that the Godot auto-complete thingy can recommend me possible strings when I want it to, and that I don’t have to update them all manually (in other places in the code) if I decide to change their text/name?

Some additional information

Also, at one point I had an enum-list system to do this, but I didn’t like it because I had to write the effects twice, as well as make sure the enum values and list indexes were set up correctly and:
"effects": [effect_list[effect_enum.effect_name1], effect_list[effect_enum.effect_name2]]
Doesn’t feel good or nice to write or to look at.

Create the effect names as constants and use them to define the dictionary keys:

const EFFECT_GLOW:String = "glow_effect" 
const EFFECT_DULL:String = "dull_effect"
const EFFECT_MOO:String = "moo_effect"
const EFFECT_BOO:String = "boo_effect"
"GROUP_A": {
		"A1": {
			"info": {"effects": [EFFECT_GLOW, EFFECT_MOO], ...},
			"visuals": {...}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.