I’m scripting combat for my game, and I so far am splitting up most of my functions into individual modules. Is this a bad practice? I don’t know much about how modules work. I just really like having organized code in their separate scripts.
This Melee module contains all those modules like in the second picture, and then a CombatController or “system” actually handles using those functions.
It’s really what you personally benefit from; if you would benefit from a system that was split into many separate parts then have that system in many parts.
I personally would have it all in one script but that is just my preference.
Alright, I was just worried that the amount of modules would do something. I plan to create many more, for different combat systems (for example, ranged)
It’s really up to you in the end, if you feel like having the functions split into modules like you currently do is working and you’re happy with it keep doing it, don’t worry about people telling you its a bad practice everybody codes in their own ways.
I wouldn’t split too much because it’s easier for me to scroll than switch between scripts. I think that these are functions of one category and should be in one module.
I used to have all these modules in one script, but I just got tired of scrolling through all the functions trying to find one. So far this is working better for me.
Maybe in the future you will need to use a global variable and these functions will not have access to it or you will be requiring a certain module in all of these scripts and when you decide to change the name of the module or replace it with a different one, whatever, you will have to edit every of these small modules.
So keep that it mind, because you don’t have to give up the idea of splitting the code like that but try to prevent these situations from happening.
Looks like you’re over-engineering. In my experience, unnecessary abstractions and over-modulation leads to less robust code, which is harder to modify for new features. This is because your existing system will not necessarily meet the future demands of what you have in mind for your game, forcing you to work around the way you’ve set it up already rather than implementing changes which would be trivial for a less complicated/‘abstract’ system.
I can’t see your actual code, but I would never put EndBlock and StartBlock into different modules–to me, that would be hard to manage and unnecessary. I would presume both use similar logic, so there’s no reason to modularise them.
I like to modularise my code according to “systems,” and only modularise further when absolutely necessary. Here’s some examples:
There are several different “modes” of pathfinding, but they’re all bundled into one module because they follow the same general logic. This greatly reduces development time when I want to make changes.
NB CharacterData handles positional and other data for the zombie’s target
Or here’s my client-side modules:
If a module sounds like it’s just one function, like StartBlock, it shouldn’t really be a module. There are exceptions to this–like in my Effects module, both Shoot and Sound simply return functions. This is because Shoot (handling both local and replicated bullet effects) and Sound (handling all sound effects) are called from many different places, so it wouldn’t make sense to bundle them together.
The roblox Chat scripts are a very bad example of this, because they’re over-engineered to hell. As a result, it’s practically impossible to modify the default chat scripts to your preference beyond a few provided settings (and the code is hard to understand). The amount of modules in the Explorer window literally doesn’t fit my screen, and it just wastes everybody’s time.
having to open several modules just to make changes to one system seems more like a hassle to me
in your case I would personally have one module per combat type (Melee, Magic, Ranged, etc)
as for this you can Collapse All Folds in the script actions menu which will make all inner functions/tables collapse (you can also click the arrow next to functions to collapse them completely which is what I usually do for functions I’m not currently editing)