Hardcoded values are a nightmare - Coding pattern suggestion for devs

Users who are viewing this thread

Hello. We don't have a suggestion section for modding related issues so I'm posting this here. I'm working on a mod currently and I'm amazed by the amount of hardcoded values I've found. This makes it very hard to mod since we don't have much flexibility and we have to patch the whole function by copying all the code, resolving references by passing in long arguments or fetching private fields/methods through reflection just to change that value. There are constants defined in classes which are essentially dead variables since the devs don't use it. Why would you do that. I know it's EA, but it's gonna hurt you in the longer run and it's hurting us modders that want to mod the game in it's current state and not after it gets released.

For example, Imagine a basic mod that tones down the skill range from 300 to 150. If you have a maxSkillLevel constant in a class and use it everywhere, then I'd only have to change that. Any other place which requires certain values like 250/275/225 in calculations, you could calculate those by modifying that constant so that If I change that constant alone I wouldn't have to swim through a sea of code to look for other changes I have to do. That's good code design. It saves everyone the hassle to change code at 20 different places when you can manage by changing in 1 place.

Similar is the case for perks. While you have every information stored inside the perk, the level limit for the final perks above which you get x% bonuses like "Every skill level above 250 gets you 2% bonus" are hardcoded elsewhere wherever that perk is getting used. If you can add another constant inside the perk class, this reduces the work for you (incase you decide to change things later on) and the modders.

In short, please use constants/variables defined inside classes instead of hardcoded values or local variables in functions.

I strongly support this suggestion.
On the whole, modding potential is fabulous, but sometimes you just tumble on such weirdly protected variable/function and you need to jump through hoops to find a workaround.
There are constants defined in classes which are essentially dead variables since the devs don't use it. Why would you do that.
I'm pretty sure the compiler does that for optimization. The devs use the constants in their code, but at compile time they are replaced with the literal value. Really the only solution here for us modders is the devs abstaining from defining const values, but that comes at the cost of a performance hit (probably very small in most cases).

I think the best solution is if modders can request particular constants to be made non-const. The devs can then review if there would be any non-negligible performance impact, and if not, remove the const modifier in an update.
Top Bottom