So enums… they have been the bane of my existence for longer than I care to admit. I structured my bonus system around them and I plan to have TONS of bonuses so it’s important the list be alphabetical.
I’ve been too stubborn to make a post about them over the past couple years as they seem like they should be so simple, but they continue to just ruin my day over and over again and now at this point I don’t even want to think about how much time and motivation I have lost dealing with this forsaken things! So I’m finally breaking down and making this post.
If I create enums like so:
public enum zxBonus
{
None,
Anger,
AfterShocks,
Behemoth,
Berserker,
BlackJack,
Block,
It’s simple, but at any point I rearrange or add to the list all existing references get garbled.
public enum Bonus
{
Behemoth = 3,
None = 0,
Anger = 1,
AfterShocks = 2,
BlackJack = 5,
Berserker = 4,
}
If I set it up like this, it becomes a messy nightmare and things get out of alphabetical order and once I have a decently sized list it’s a pain. It just feels wrong.
I’ve gone so far as to create custom classes that store a secondary string value and then accesses the enum from that string:
[Serializable]
public class SafeBonusReference
{
public string enumString = "None";
[ShowInInspector] public Bonus bonus { get { return DataManager.GetBonusEnum(enumString); } set { enumString = value.ToString(); } }
}
public static Bonus GetBonusEnum(string name)
{
foreach (var enumName in Enum.GetNames(typeof(Bonus)))
{
Bonus checkedEnum = (Bonus)Enum.Parse(typeof(Bonus), enumName);
if (enumName == name) return checkedEnum;
}
print("enum Not Found for " + name);
return Bonus.None;
}
Am I just doing this totally wrong? I’m relatively new to code and it just totally blows my mind how clunky and terrible Enums are. There has to be a better solution for creating a list with names on it right? I have no idea, the more I learn about gamedev the more I see just absolutely lacking key functinality that just sits there and everyone just deals with it.
But i’d be happy to learn that there’s some super simple solution I’m just not aware of and that I’m a moron!
Another thing I’d love to do with enums but they’re just such a pain is to generate list type options elsewhere. There are so many times i’d love to have a 3rd or 4th option, but bools only allow “true/false” and if I resort to something like an int for options 1,2,3,4, etc. They don’t communicate any sort of inference of what they do. I guess I could use a string condition, but that’s prone to human error and who wan’ts to constantly deal with quotation makes?
Hope I’m properly communicating all these problems, I’m burned out from dealing with these things all day for the 50th time and can’t even think straight.
Bonus question… I have several classes that I’d love if they just automatically returned a specific type of value. So in the above class if I want to get the bonus value returned I have to type
“safeBonusReference.bonus”
Is there any way to get this class to return the Bonus by default by just typing “safeBonusReference”

