A very common format I find myself using is to create an enum alongside a packed array to index data out of the enum.
For instance, I have “Stats" for units in my game, where each value in the table stores
[ Range, Health, MaxHealth, etc… ]
This is very practical as it lets me make effects that hinder of buff an arbitrary stat by just swapping an enum.
For instance, I could have an attack that lowers a given stat from a unit by 3 with Stats[ENUM_VARIABLE] -= 3
The downside is that it makes the data very painful to set in the editor, as I just have to “remember” that enum value 5 is “Move Distance” and so on, leading to a lot of objects in my editor looking like this:
(making it very annoying to keep track of what value marks what data, especially whenever I add a new stat to the enum forcing the list to change size)
Does Godot have a way to display the names of each index as enum names instead of integers?
Or at the very least, is there a way to manually rename each element in an array so I can tag one as their respective stat name?
Probably better to extend a resource for StatCollection(s). I can’t imagine you’d want to iterate over different as an Array or dynamically add or remove stats, so it’s not necessarily a good fit as a data type
I don’t need to add or remove data, but iterating over them is actually pretty useful for displaying a list of stats in the UI.
But most importantly, keeping it a table that’s indexed with an enum allows me to create other scripts in the game that modify a variable stat.
If the StatCollection has a specific variable for “Health” or “Damage”, then I can’t easily make another script that modifies “Health” or “Damage” without making effectively two copies of the same script that just modifies a different variable.
yea but packed data is realllll nice
especially in my case as I have a lot of units and cells I want to manage at once- a dictionary feels like overkill if I’d just be using it to make the editor read a bit better
Not to mention, I kind of need the enum’s ability to be iterated over / compared to a specific integer. I’m using it for a glossary in my game used in my tooltip system, so indexing a dictionary with a string is a bit out of the question
It may fell like it but it isn’t. Why would it be an “overkill”? A dictionary with an enum key is perfectly fine for this, although I’d just use a Resource class as @gertkeno already suggested.
My test room has an upper limit of 2,359,296 on a 1536x1536 grid
I probably never need to go this high, but I do enjoy optimizing how my project stores data.
I still really want the benefit of being able to index a specific stat using an enum, so I’m holding off on a resource as well.
I’m less asking for another approach, and more asking if there’s a way to just change the editor to show enum names next to the elements in the array instead of raw integers