Hello! I have a general optimization question, regarding functions and input.
Consider an elemental damage system. There are different damage types, with different logic and variables each. However, they all share common attributes (damage value, source and target). I am making a health system Actor component. I thought one way to approach this is having all the logic and input in one function and use an enum to select a type like this:
Your question requires a very complex answer because there are so many different ways to do it. The good news is, whatever way you decide to do it will be fine because you will mold it to fit your approach. Don’t confuse quantity of code with optimization. The fact that you have repetitive functions does not necessarily mean you will suffer gameplay performance. You will just suffer the chore of making changes in many places but that chore will make you learn more about how to model the code. Either of those solutions you posted would work and starting with either one will likely be fine.
Don’t go down the rabbit hole of perfect code. It gets in the way of making a game. Pick a way, do it, step back and evaluate what you don’t like. But evaluate it by hitting “play” and watching it work, don’t evaluate it by looking at the blueprint. The most important part is how it feels. If there is something you don’t like, when you go to fix that you will then learn what you don’t like about the code and you will enhance it so adding gameplay changes will be easier.
Thanks for your response. I just looked at my situtation and it seemed a fairly easy thing to code, but when I looked at my code I just thought that I am missing something much simpler, and I was afraid that this was not a good, maybe even a bad way to do it. I guess as long as it works and doesn’t make my computer go crazy…it’s fine.