Is this bad practice?

My framework has a lot of content in it, and I am trying to think of ways to access different needed modules.

local self_modules = {
	dictionaries = {
		loaded_effects = require(script.dictionaries.loaded_effects)
	}
}

--module functions--
function module.register_effect(host: Instance, numerical_property: string, multiplier: number)
	local loaded_effects = self_modules.dictionaries.loaded_effects

	if not loaded_effects[host.Name] then
		loaded_effects[host.Name] = {}
	end
	
	if not loaded_effects[host.Name][numerical_property] then
		loaded_effects[host.Name][numerical_property] = {}
	end
	
	table.insert(loaded_effects[host.Name][numerical_property], multiplier)
end

I have a list of needed modules located in a table,
image

and I have specifically needed modules in the function itself.
image

Any feedback with this method?

1 Like

Hi, this all seems like a viable approach, but I would recommend using OOP( Object Oriented Programming ) for instance, instead of using the three arguments: host, numerical_property ( which a string… odd…) and multiplier, you could create a class “effect” which stores the arguments as fields. Roblox natively supports classes using metatables( trust me, they aren’t as complicated as they sound… ) . This way, you can pass an instance of the “effect” class into the register_effect function instead of three arguments, resulting in a more optimized codespace. Furthermore, I would recommend explaining your code with more comments as your datastructure is rather confusing ( I have no idea what you are trying to achieve with this program…)
Overall, your code would benefit from a more dynamic, object oriented approach. :wink:

PS. LuaU does not have “dictionaries” they are more commonly referred to as “tables” or “arrays”. :nerd_face::bulb:

Can you give an example of what you’re talking about?

1 Like