Forest Logo
search
package_2

event

By @rt0mmy

Roblox

Mirrored

Event

Fast & Lightweight Luau scriptevent

Luau





Warning
Event is under development



Why Event?

Event is an API meticulously crafted to simplify event management, making your code more readable, maintainable, and responsive; It's lightweight and straightforward structure makes it extremly easy to implement into your workflow.

Event offers intuitive and clean API structure, designed to minimize complexity while maximizing functionality.

Empower your projects with the blazing fast Event




API

local Event = require(...)



Creating a new EventObject

Event() -> Event
local newEvent = Event()



Creating a new Connection for the specified Event

EventObject:Connect(Callback: (T...)) -> Connection
local newConnection = EventObject:Connect(function(a: number, b: number)
	print(a + b)
end)



Creating a new single-use Connection for the specified Event

EventObject:Once(Callback: (T...)) -> Connection
local newConnection = EventObject:Once(function(a: number, b: number)
	print(a + b)
end)



Creating a new asynchronous Connection for the specified Event, thus yielding the runtime code until the event is triggered. An optional timeout argument defines how long the code will yield until the Wait method is terminated and therefore fails.

EventObject:Wait(timeout: number?) -> Connection
local success = EventObject:Wait(2)
print(success)



Disconnects the Connection from Event

ConnectionObject()
newConnection()



Fires the event, triggering all Connections (Callbacks)

EventObject:Fire(T...) -> nil
EventObject:Fire("Hello World!", "\n Luau is great!")



Terminates all Connections from the Event

EventObject:DisconnectAll() -> nil
EventObject:DisconnectAll()



Destroys Event, therefore also disconnects all Connections

EventObject:Destroy() -> nil
EventObject:Destroy()




API Sample Demo

local Event = require(...)

local newEvent = Event()
local newEventConnection = newEvent:Connect(function(...string)
    print(...)
end)

newEvent:Fire("Hello", "World") -- // -> Hello World

newEventConnection()
newEvent:Fire("Hello", "World 2") -- // Doesn't print "Hell World 2", because the ConnectionObject "newEventConnection" was disconnected beforehand.


local Event = require(...)

local EventProcessAB = Event()

function ProcessAB()
	local v = EventProcessAB:Wait(4)
	
	if v then
		print('A + B = '..v)
	else
		print('failed to deliver :(')
	end
end




-- Script A

local Event = require(...)

local ClientEvents = {
	onClientDead = Event(),
	onClientDamaged = Event(),
	onClientStatusChanged = Event()
}

return ClientEvents

-- Script B

local ClientEvents = require(ScriptA...)

local function TakeDamage(n)
	...
	ClientEvents.onClientDamaged:Fire(n)
	if Client.Health <= 0 then
		ClientEvents.onClientDead:Fire()
	end
	...
end

Package Details

Install command (Click to copy)


Version

0.1.0

License

MIT

check_circle

Safe for commercial use

Automated license review — not legal advice.