Too many modules?

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.

https://gfycat.com/EnchantingMindlessKingfisher

Here is what the main module looks like.

1 Like

I do too, like organizing code in modules, but I think spitting it by “systems” might be easier to manage when you have a handful of code to handle

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.

1 Like

But is it going to affect performance? That is what I am worried about.

1 Like

I may be wrong, but i think that falls into the micro-optimizations which you shouldn’t worry about

1 Like

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)

1 Like

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.

3 Likes

What I meant was that handling lots modules in a module might be hard to manage over time

Oh yeah, I can see that happening over time.

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.

I am using aero game framework, so I don’t really have a problem with accessing other scripts or variables. But yeah, that is something to consider.

2 Likes

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:

image

  • 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:
image

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.

3 Likes

1 module = 1 system is what I do

image
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)
image


to

and these are small functions, it’s even more useful when the functions are larger

6 Likes

Yeah, I agree. I have moved everything back into the main module.

I totally forgot about this, thanks!

Holy, I had no idea about that folds thing. Makes code way easier to navigate.

2 Likes