Eventify - Simple custom event module

I decided to have a go at making an object-oriented custom event module as I was bored, so I created this super simple & easy to use module!

Download Eventify

The usage is super simple, below is some sample code!

local Eventify = require(game:GetService("ServerScriptService").Eventify)

--// Create a new event
local Event = Eventify.new()
--// Connect a function to the event
Event:Connect(print)
--// Fire the event!
Event:Fire("Hello world!")

It also comes with some additional functions, such as Event:DisconnectAll(), Connection:Wait() and Connection:Disconnect()

Function Reference
function Eventify.new(Name: string) -> Event
   Creates a new event object
      - The name argument can be used to access the event across multiple scripts
function Event:Fire(...) -> void
   Fires all connections in of the event with the inputted arguments
function Event:Connect(Callback: function) -> Connection
   Creates a new connection
      - The callback argument is a function which is called when the event is fired
function Event:Wait() -> void
   Yields the thread until the event has been fired
function Event:DisconnectAll() -> void
   Disconnects all event connections
function Connection:Disconnect() -> void
   Disconnects the connection

Thank you!

Source Code
local Eventify = {}

local EventCache = {}
local ConnectionCache = {}

local Event = {}
Event.__index = Event

local Connection = {}
Connection.__index = Connection

function Eventify.new(Name: string?)
	if Name and EventCache[Name] then return EventCache[Name] end
	local NewEvent = {}
	setmetatable(NewEvent,Event)
	ConnectionCache[NewEvent] = {}
	if Name then
		EventCache[Name] = NewEvent
	end
	return NewEvent
end

function Event:Connect(callback: (any) -> any)
	local NewConnection = {}
	setmetatable(NewConnection,Connection)
	
	ConnectionCache[self][NewConnection] = callback
	
	local event = self
	
	function Connection:Disconnect()
		ConnectionCache[event][NewConnection] = nil
	end
	
	return NewConnection
end

function Event:Fire(...)
	for _,Callback in pairs(ConnectionCache[self]) do
		task.defer(Callback,...)
	end
end

function Event:Wait()
	local IsWaiting = true
	local Connection = self:Connect(function() IsWaiting = false end)
	repeat task.wait() until IsWaiting == false
	Connection:Disconnect()
end

function Event:DisconnectAll()
	ConnectionCache[self] = {}
end

return Eventify
6 Likes

What is the difference between this and GoodSignal, and why should this be used over the other?

2 Likes

GoodSignal is far superior to this module.

I made this module for fun & it’s their for anyone who wants to use it but I’d recommend just using GoodSignal instead for production projects

Might as well let anyone who wants to use it, use it.

Plus I believe it’d be more lightweight than GoodSignal, not entirely sure though.

Community Resources is people who wish to give away resources to the community in which they’ve created. It’s up to others discretion if they use this over something such as ‘GoodSignal’; on top of that this isn’t necessarily a bad resource to learn off of for basic entry.

@Starnamics Don’t undervalue your work; this isn’t bad by any means. While there are some rooms for improvement, it serves its purpose unless we’re getting in to microperformance.

Nicely done! :slight_smile:

7 Likes

There needs to be a distinction made between work which is original from other alternatives, and posts that essentially litter the category. Your argument is very dangerous, for it could go down a slippery slope of allowing any type of posts, with the reason of ‘they’re learning’.

1 Like

Taking inspiration isnt a copy, and what if they don’t know that GoodSignal exists?

2 Likes

I highly don’t recommend you to use one of my work as a rebuttal as this could have be deemed as off-topic.

Commander is not the first administration system in Roblox, it follows some standards from other existing administration systems. However, it has some unique features that really stands out and justifies its existence in the community resources category.

Similar product is fine, but if it doesn’t have any unique features compared to existing products, there’s not enough to convince others to switch over or adopt.

2 Likes

@Starnamics dont mind pyseph, i made a module like this just a few days ago and he was up in my thread spreading the same negativity. none of us are here to be the best, we are just here to share what we can do. great job!

2 Likes

This was completely not needed. The community resources category should not be locked for already existing resources. The whole point of this category is to share what you make, as it relates to Roblox development, with the community. If you think it’s “subpar” then don’t use it; don’t harass the creator claiming “better stuff exists so this is pointless.”

You don’t know how much effort they put into this resource. Just because it isn’t up to your “standard” doesn’t mean it’s useless. Also attacking someone’s work and then shielding your own work when the roles get switched is kind of silly. Don’t post just to criticize someone’s resource unless you actually want to contribute to making it better.

@Starnamics Sorry you had to deal with these people. Keep up the great work!

1 Like

Sure… I don’t think a signal library is that hard to implement. This is very alike Reselim’s implementation except it uses the task library, not the coroutine library

I am not? Not so sure how do you think but having discussion about another librarys/toolings that has no relation with this one… it’s just weird and technically can be flagged as off-topic.

Even if it was not difficult, I still spent time making it.

The relation is that you were saying mine was not beneficial as there are others that are similar, so I was saying the same about admin systems, which there are plenty of but people still use different ones instead of the most popular ones.

Again, completely not needed. Stop shaming people’s work. This resource may be beneficial to some people. If you don’t like it, don’t use it and don’t harass the creator.

2 Likes

Its sad to see fellow devs discouraging a resource just because it’s similar to others.

Original idea or not, @Starnamics went out of their way to make a resource to help us devs.

You should learn to appreciate that.


@Starnamics Please don’t undervalue your work and don’t let other devs discourage you from making modules like this.

You put effort into this module and had good intentions. Thats what matters.

6 Likes

This isn’t littering the category - it’s open source, and really is nothing compared to what is sometimes spammed here. Regardless of if there’s a better alternative or not, this isn’t hurting anybody, it’s simply an alternative, especially if you the user wants to understand how a module like this is made, since many of these other modules like GoodSignal are rather complicated for a beginner to understand.

tl;dr aside from blatant spam, having more resources does nothing but benefit developers.

8 Likes

I totally agree. If anyone is littering anything, its pyseph. I made a signal module post here a few days ago and pyseph was in the thread doing exactly the same thing, putting down my work by asking how its any better than an existing thing. He seems to only care about putting down others work rather than praising any sort of accomplishment they may have made, appreciating the good intentions, or acknowledging that a simpler module may not perform as well but may be much easier for a beginner to understand and expand upon.

3 Likes

I don’t really think a distinguishment needs to be made versus other solutions. The whole purpose of this category is to allow developers to share their work for others to use and learn from.

While you may have not intended to sound degrading, it comes off as such because you are essentially telling anyone who views this thread to not use it because there are other resources that share similar concepts.

3 Likes

There is an irony to be made, as none of our posts, including my own, are relevant to the topic of the module. If you would like to properly discuss the correctness of my post, my PMs are open.

He clearly made it for fun, And theres no problem with that. You go to the store, you see two similar products, one simpler and another more better, It does not matter which one you buy as its your choice, and your allowed to make similar products. Which proves your point wrong.

If you always want to see “useful” and “original” resources then make your own.

You made some dude delete his resource that I find useful. You are totally literring. Please stop.

1 Like