Hello i have recently made a module that can be easily used by others and look clean
this module can show all examples of functions ( you do require to make them though )
This contains stuff like :
Classical functions for users to understand the module
Functions from the creator of the module
Variables from the creator of the module
Changable Variables from the creator of the module
Module Maker Asset
You can get this asset 3 diffrent ways These diffrent ways are :
1) Original script (V1)
Script
-- Module Start (Do not change) --
local Module = {}
local ModuleExamples = {}
-- Module settings --
local ModuleVersion = 1 -- The version of the features of the module
local ModuleName = "Module Maker" -- The name of the module
-----------------------------------
-- Module classic functions --
function AddExample(Example:string)
table.insert(ModuleExamples,Example)
print("Added example")
end
function Module:Info()
warn(ModuleName .." module | V" .. ModuleVersion)
end
function Module:PrintList()
warn("Listing functions,variables")
for i,v in pairs(Module) do
if type(v) == "function" then
print(i.. " | Function")
else
print(i.. " | Variable")
end
end
end
function Module:GetExamples()
for i,v in pairs(ModuleExamples) do
if v ~= nil and type(v) == type("") then
print(" -- Example "..i.." --")
warn(v)
end
end
if #ModuleExamples == 0 then
warn("No examples were made")
else
print("-------------------")
end
end
-----------------------------------
-- Variables --
-----------------------------------
-- Changable variables --
-----------------------------------
-- Functions --
-----------------------------------
-- Returning the module back --
return Module
-- Functions --
AddExample([[RequestAllClassicFunctions()]])
function Module:RequestAllClassicFunctions()
Module:Info()
Module:PrintList()
Module:GetExamples()
end
-----------------------------------
Changable Variables
-- Changable variables --
task.spawn(function()
while task.wait() do
Module.LocalPlayer = game.Players.LocalPlayer
end
end)
-----------------------------------
Any suggestions for this module to have would be appriciated
Hi! I really don’t know what we are supposed to do with that. It’s not really helping(not too advanced) anyways it can help begginers at modules, i don’t see another utility .
This is supposed to make modules look more clean and the players who use them can get more info about the module they are using from the classic functions of the module
making it easier for them to use it
Pretty true but it will be for more “advanced” programers. Begginers and average programmers can’t simply use what you just did here. I’m more fine to see people using the “bad/original” versions instead of making errors with that.
As an experimented programmer i will don’t recommend to use this way first, i think it will more simple to do the “basics” functions for the module.
i mean surely its not the worst thing but its just not the most organised thing and some people who use the module could be confused since the only way to find how a functions from the module you made is by reading the code and not many people know how to do that or it just might be hard understanding that.
here is a example
Normal Module
function GetHumanoid(PlayerCharacter)
PlayerCharacter:FindFirstChild("Humanoid")
end
A Module with examples
AddExample([[GetHumanoid(game.Players.LocalPlayer.Character]])
function GetHumanoid(PlayerCharacter)
PlayerCharacter:FindFirstChild("Humanoid")
end
if they use GetExamples() they will claim all of the examples of each function made in the module
I always learned/teached programming like that and most of programmers i have meet is doing in my way and see what you do more difficult to learn first, i assume it can be confused to read but if you know how and why it’s, it’s very simple to read.
well sure thats true but thats not the point
the point is you can understand what a function does without wasting much time knowing exacly the code and even better for people who dont know that much coding they can understand how it use it.
The more a developer adds to the module, the more messy it will look. I understand what your intentions are, but the module doesn’t seem like it’ll help in that regard.
It would be better to create a module that developers can utilize for runtime documentation inside scripts:
-- Example
local docsModule = require(path.to.module)
local moduleScript = require(path.to.module)
-- The developer can add documentation to the module here
-- function docs.add(string name, string description, string codeSample)
docsModule:add(
"Method Example",
"An example function",
"local result = ModuleScript:add(1, 2)"
)
-- the actual method here:
function moduleScript:add(a: number, b: number): number
return a + b
end
-- then the developer can retrieve the documentation
-- function docs.getDocs -> {DocumentInfo}
for _, data in docsModule:getDocs() do
-- would print (Method Example: An example method)
print(`{data.Name}: {data.Description}`)
end
It may be better to just pre-compile a documentation list inside a ModuleScript, but this is just what I came up with.
A plugin that automatically reads through a script’s comments and displays documentation to the developer in a widget would also be useful
This method would be highly inefficient. Instead of using a continuous while loop, you should use the GetPropertyChangedSignal method to update a property of the module.
the thing is most of the modules people have made are really not self explanatory and this is why i made it
i had to take time trying to find which function did what even know i know enough coding to know
but yet its not hard to be lost or confused on a module that you didnt made
without enough examples you just kinda get lost at that point
This is applicable to your case if you want to maintain an updated property within your module. The optimal approach for updating a module property when an instance property changes is to listen for an event. By listening to an event, the module property is reassigned only when the instance property changes. Using a continuous while loop results in unnecessary reassignment of the property value, even if the instance property remains unchanged.
To achieve the desired outcome, you should use the GetPropertyChangedSignal method on the instance. The goal is for a property of the module to mirror the property of an instance, rather than the other way around.
@nikos300 In the given example, the instance referred to would be the Players service, as you are indexing its LocalPlayer property.
@VSCPlays I am not relying on ChatGPT for my responses. Instead, I am drawing upon my knowledge of Luau. When it comes to utilizing a method that involves an event, leveraging the event is typically the preferable choice. This is because utilizing an infinite loop can lead to unnecessary script activity and adversely affect performance by consuming more memory.