I was making a class and I wanted a way to elegantly add events into the class, and so i made this! This is my recreation of ROBLOX’s Signal class, with the only difference being that it doesn’t have the ConnectParallel function.
Here is an example of me using the Module.
(this is purely an example to show you how it works)
local Event = require(game.ReplicatedStorage.Signal)
local OnPartAdded = Event.new()
game.Workspace.ChildAdded:Connect(function(Part)
if Part:IsA('BasePart') then
OnPartAdded:Fire(Part) -- Fires the event whenever a BasePart is added to workspace
end
end)
local MyConnection = OnPartAdded:Connect(function(Part) -- Runs whenever the event is fired.
Part.Size = Vector3.new(5,5,5)
end)
OnPartAdded:Once(function(Part) -- Runs When the event is fired and then disconnects itself.
Part.Position = Vector3.new(0,30,0)
end)
local Part = OnPartAdded:Wait() -- Yeilds until event is fired.
Part.BrickColor = BrickColor.new('Hot pink')
delay(5,function()
MyConnection:Disconnect() -- Disconnects MyConnection after 5 seconds.
end)
there are better alternatives, i just enjoy trying to do things myself before i use something made by someone else. + it fits my needs fine so im happy with it.
Um… what? One of the most important tips of programming is not to reinvent the wheel, it’s a waste of time. Why would you want to make something worse and use it just because you made it…?
And of course it may fit your needs, but why wouldn’t you want something with more features? There’s something called scalability.
sorry if I didn’t clarify enough but for most of my projects I do use pre-made modules (such as ProfileService), however for this it was a relatively simple task and I wanted to try doing it myself.
Although I probably would not use this, I appreciate you for sharing your work for people who may need it / want to learn from this despite what others say, great work lad
Then give them some constructive criticism on how to make it more “secure”.
Learning and putting out your work shouldn’t be something you’re scared of because the community is toxic. Honestly it’s smart to try things yourself before using a resource made by someone else so you can actually understand the concepts and how it functions.
Honestly everyone here bashing OP and their work needs to provide constructive criticism. Telling someone their work is trash, and having no solution will not get you far in life. I don’t see a problem in reinventing stuff, as it makes you grow as a programmer. If we didn’t reinvent/comp things how would you learn how things work?
Great job on this module. I looked through your code and noticed there wasn’t a destroy method, which you should consider having one. That way people who use Trove, and any other GC tools can easily plug the class into it, as it would have a destroy method. Also any method that you start with an underscore such as; :_[methodName] is a private function which should be in camelCase, as it’s not used outside of that source.
In addition wrapping your methods in a do - end doesn’t seem necessary personally. Not sure if it was to help for readability would like your insight for this.
The do statements are entirely so that I can collapse them and see what they are. It provides nothing for the actual code and is entirely a thing I do for readability.
Also I will add a destroy method into the class. Thanks for the feedback!
I see this in many resource posts, I dont understand why people feel the need to bash on someone elses work and provide no criticism and just outright call it useless / trash. If you have nothing good to say or dont even bother to provide criticism / have no use of the resource, its quite simple to just ignore the post and move on with your day.
It is ridiculous how there are people nice enough to share their work to everyone yet we have people who’s first thought is “Why would we use this over [other resource name]?” or some other bs. This is why I rarely ever post on the forums and would rather spend my time just browsing posts, its just litered with negativity and people going against each other, there needs to be more people helping each other solve their issues and giving them useful pointers on how they can improve.
Sorry for criticising on an open forum? This is a resource meant for helping others, why cannot people ask benefits of using this? Not all development is rainbows & roses…
do-end statements change the scope of variables, just like putting local variables in functions it changes the scope of those variables. Here is an example.
local foo = 123
do
local foo = 321
end
print(foo) -- outputs: 123
I’ve found that a lot of the time, the best way to understand the great resources that others provide is to make it myself, regardless of if it’s not as good as the alternatives.
Thank you for sharing this, it can be utilized by others to better understand how to approach signals and I hope others will provide constructive criticism to help your code. If someone else can do it better they should show how, so that others that look on this post can learn from it as well.