Module Script Functions

I have a module script where it has a couple functions but there not set up as usual. I just need a way to call the functions.

Script

local module = {
	
	["print"] = {
		Function = function(speaker,args)
			local printMsg = ""
			for i,v in ipairs(args) do
				if i > 1 then
					printMsg = printMsg .. v .. " "
				end
			end
			print(printMsg)
		end
	}
	
	
}

return module

local example = require(Module)

example.print.Function(Speaker, “hello world”)

Here’s a hyperlink to a code sample on the wiki:

Edit: see the post below, he covers it well:

The way you have it, if you need to call the function you would need to do

local module = require(where it is)
module.print.Function()

The function you have is inside of a table associated with the "print" key, module.print retrieves the table, module.print.Function retrieves the function inside of that table, () calls it.
Instead, "print" would simply equal the function, that way you simply call module.print()

In addition, this is kind of unecessary, the

function module.print()
    --body
end

syntax sugar is way nicer, and offers more readability, hence more maintainability.

3 Likes