Too many parameters?

Hey. I’m currently working on a particles system. While working on the class which is responsible for spawning the particles, I realized that I would require the use of many parameters. Currently, there are a total of 12 parameters required to create a new object.

It looks a little something like this:

function Particles.new(model, origin, directionRange, intialVelocityRange, accelerationRange, lifeTime,
dragCoefficient, gravityEnabled, collisions, inheritsOriginVelocity, restitutionCoefficient, spawnRate)
local self = setmetatable({}, Particles)
-- Settings:
self._model = model
self._origin = origin
self._directionRange = directionRange
self._intialVelocityRange = intialVelocityRange
self._accelerationRange = accelerationRange
self._liftTime = lifeTime
self._dragCoefficient = dragCoefficient
self._gravityEnabled = gravityEnabled
self._collisionsEnabled = collisions
self._inheritsOriginVelocity = inheritsOriginVelocity
self._restitutionCoefficient = restitutionCoefficient
self._spawnRate = spawnRate

-- Variables:
self._activeParticles = {}

-- Connections:
RunService.RenderStepped:Connect(function(dt)
	self:update(dt)
end)

return self
end

(Sorry for the weird indentation the formatting was not playing nice with me lol)

Now, as you can see, having that many parameters is a real eyesore. I would love to hear some suggestions on how I can potentially shorten down on the amount of parameters used or make it look nicer at least. Thanks.

1 Like

Maybe just store the parameters in a table and get the variables via the table’s index? That’s what I did for my custom objects.

local particlePhysicsSettings = {directionRange, intialVelocityRange, accelerationRange,dragCoefficient,gravityEnabled,collisions}
--Yeah 
local newParticle = Particles.new(model,origin,particlePhysicsSettings) 

Edit: Or set default settings for stuff like gravity so you can just change the dot variable later like a normal Part instance

--default it's false
newParticle.inheritsOriginVelocity = true
1 Like