local module = {}
local valTable = {}
function module.MouseButton1_Attack()
end
function module.MouseButton2_Attack()
end
function module.HitDetection()
-- returns true or false
end
function module.DealDamage()
-- Deals Damage to target.
end
return module
Let’s say this script wants to temporarily store some values in the above table ‘valTable’, is there any reason I couldn’t just put it into module…? and if I do put it into module I can also access those values by simply requiring the script rather than needing a func to return the other table.
Is this how you’re supposed to use modules? for the longest time I’ve been making a separate table to store any values while using the main ‘module’ table for storing functions.
Exactly! I don’t know why I’ve not been doing this already… I think I saw somewhere that someone did it this way and just kinda went along with it? Just to confirm, the main reason for asking; are there any downsides to doing this or is it acceptable / expected?
When you add something to the module, it increases the memory usage when you require that module (because it returns more data). Generally speaking, this is not an issue.
In your particular example, the only thing that would change if valTable is a subtable inside module is the encapsulation of valTable. You might have reason to not want to expose it, such as forcing access to go through getter and setter functions for debugging reasons, or preventing a constant value from being externally modified.