Is there better way to require this module?

Hi, i started learning OOP and i combined it with my old strat i call “Micro-Modules”

This strat utilizes small modules with one function named the same in every of them, but you can give different propertiess depending on Object and write specific function.

Explanation of Micro-Modules

For those who don’t understand what i’m talking about, let’s say we have 3 attacks:

  • fire
  • water
  • wind

And all of them do some unique function, to achieve this unique function and make it easy to code i use 3 different lightweight modules for that, each module have function Power:Calculate()
that can be called from object that should own this type of power, inside this function i can write 20 lines of code that deal damage or checks if player is hitted or not

function VFX:__init(effectType:string,effectPropertiess:{})
	self.effectType = effectType
	self.effectPropertiess = effectPropertiess
	
	local Calculation = require(Calculations[self.effectType])
	self.Function = require(Calculations[self.effectType])
	
	local ID = effectType..(effectPropertiess.ID or "_default")
	Objects[ID] = self
end

function VFX:Play(origin:Vector3) : void 
	local Calculation = self.Function
	Calculation:Calculate(origin,self.effectType,self.effectPropertiess)
	
	remote:FireAllClients(origin,self.effectType,self.effectPropertiess)
end

I have two options:

1 - Require module every time function :Calculate() is called
2 - Require module on object creation and then add Function property to it with required module

Which option is the best? and is there any alternative?

1 Like

Hello, I don’t quite understand the issue at hand here but I’ll do my absolute darnest to help ya.

So from what I’ve understood you are having issues with loading your “Micro-Modules”, Wich in this case I assume they are VFX modules.

For the first option and here’s where I had the most trouble understanding because there is no :Calculate() method it only gets called.
And lastly the last option and the one you should opt for is the one I suggest going for!

And the solution I came up with is loading all the “Micro-Modules” on your VFX class, effectively pre-caching them and reducing overhead when multiple VFXs are being played!

Hope you find this helpful :wink:

4 Likes

Soo leave this when creating VFX and save it under it is good idea, thx for making me sure to go this way

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.