Hi all -
After a few months of practice, I feel I’m starting to reach the point where I can put something resembling an incremental 2D clicker game together.
However, I noticed that these days I quickly become overwhelmed by the sheer number of components I have to work with. For example, I have a GameController object that stores key variables such as food, wood, population etc. I then have scripts attached to buttons (such as buttons to build houses, to hire workers, etc) that reach into the GameController script to check and update their variables. I then have buttons for manually gathering food and wood, each with its own script which also reaches into GameController to impact the variables. I then have scripts that enable and disable buttons based on the contents of GameController variables. I have scripts that instantiate things. I have scripts that check for instantiated things. Given enough skill, I’d probably have scripts that wrote scripts.
In short, the longer I code, the more I feel I’m producing spaghetti code of sorts - something I can only make sense of while “in the flow” and probably would not know what to do with the next day! After a while, I feel defeated not by the complexity of the task, but by the sheer amount of variables and scripts that I’ve got to keep track of. Surely there’s got to be a better way?
Do you have any resources / references on how to code “cleaner”, for lack of a better word? Something that would help me keep things compartmentalized, manageable, and make it possible to only deal with isolated “chunks” of code when implementing a feature? For instance, should I have as many discrete scripts as possible each containing only a few functions that are closely related to what the script is trying to do? Or should I have a monster script (e.g., ButtonController) that is assigned to the OnClick of dozens of buttons across the UI?
After all, a 2D clicker game is clearly a very low-complexity project compared to professional AAA work - so if I’m struggling to handle what I built now, then I’m clearly doing something wrong.
Don’t know if the question makes sense, really - finding it quite hard to even describe the problem, other than the sense of looking at the code and going “Oh my God, this is overwhelming - and surely there’s got to be a sort of conceptual architecture of sorts out there to avoid this?”
George