From a2ca24e33c725fffccd43a9eff507a629426a409 Mon Sep 17 00:00:00 2001 From: Tazmondo Date: Wed, 3 Jan 2024 14:53:01 +0000 Subject: [PATCH 1/3] Add missing pcall to Event Server listener --- lib/Event/Server.luau | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Event/Server.luau b/lib/Event/Server.luau index 180e362..aef0194 100644 --- a/lib/Event/Server.luau +++ b/lib/Event/Server.luau @@ -82,7 +82,7 @@ end local function On(self: Server, Callback: (Player, T...) -> ()) Net.Server.SetListener(self.Id, function(Player, Args) Spawn(function(self: typeof(self), Player: Player, ...: any) - if self.Validate(...) then + if pcall(self.Validate, ...) then Callback(Player, ...) end end, self, Player, table.unpack(Args)) From 21684634a914d73880259859343614b4f29b29ec Mon Sep 17 00:00:00 2001 From: Tazmondo Date: Wed, 3 Jan 2024 14:54:27 +0000 Subject: [PATCH 2/3] bump version --- wally.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wally.toml b/wally.toml index cfff4ea..9fdfc35 100644 --- a/wally.toml +++ b/wally.toml @@ -1,6 +1,6 @@ [package] name = "red-blox/red" -version = "2.3.0" +version = "2.3.1" registry = "https://github.com/UpliftGames/wally-index" realm = "shared" license = "MIT" From fb7f6bf0163ae4946d0ec94ce1a74534771440f4 Mon Sep 17 00:00:00 2001 From: Tazmondo Date: Wed, 3 Jan 2024 18:13:30 +0000 Subject: [PATCH 3/3] Update SharedSignalEvent docs to specify that it returns a disconnect function --- docs/2.0/SharedSignalEvent.md | 12 ++++++------ docs/guide/events/sharedevent.md | 12 +++++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/docs/2.0/SharedSignalEvent.md b/docs/2.0/SharedSignalEvent.md index 20cde76..68041e5 100644 --- a/docs/2.0/SharedSignalEvent.md +++ b/docs/2.0/SharedSignalEvent.md @@ -4,13 +4,13 @@ SharedEvents are built on the same backend networking as regular events. However Unlike [SharedEvents](SharedEvent), SharedSignalEvents may have any number of listeners set. ## OnServer -Sets the server callback. +Adds a server callback, returning a disconnect function. ```lua ( Listener: (Player: Player, T...) -> () -- The listener to register -) -> () +) -> (() -> ()) -- Disconnect function ``` -This method sets the server callback. Errors if called from the client. +This method adds a server callback, returning a disconnect function. Errors if called from the client. ```lua MyEvent:OnServer(function(Player, Argument) print(Player, Argument) @@ -18,13 +18,13 @@ end) ``` ## OnClient -Sets the client callback. +Adds a client callback, returning a disconnect function. ```lua ( Listener: (T...) -> () -- The listener to register -) -> () +) -> (() -> ()) -- Disconnect function ``` -This method sets the client callback. Errors if called from the server. +This method adds a client callback, returning a disconnect function. Errors if called from the server. ```lua MyEvent:OnClient(function(Argument) print(Argument) diff --git a/docs/guide/events/sharedevent.md b/docs/guide/events/sharedevent.md index 205428d..3d2e000 100644 --- a/docs/guide/events/sharedevent.md +++ b/docs/guide/events/sharedevent.md @@ -3,7 +3,7 @@ Shared Events are simply a different way of using Events. They both use the same They have the major benefit of not needing to explicitly call `Event:Server` or `Event:Client` before being usable. Both your server and client code can simply require them and start using them. -There are two types of Shared Events: The default `SharedEvent`, and the Signal-based `SharedSignalEvent`. By default, Shared Events only allow you to set one callback function, but Shared Signal Events allow you to have any number of callbacks. +There are two types of Shared Events: The default [SharedEvent](/2.0/SharedEvent), and the Signal-based [SharedSignalEvent](/2.0/SharedSignalEvent). By default, Shared Events only allow you to set one callback function, but Shared Signal Events allow you to have any number of callbacks. This is marginally worse for performance, as it has to use a Signal to fire the callbacks - hence why it is not the default. @@ -72,9 +72,12 @@ end) Events.PayloadSignalEvent:OnClient(function(number) print("Callback 1", number) end) -Events.PayloadSignalEvent:OnClient(function(number) + +local DisconnectFunction = Events.PayloadSignalEvent:OnClient(function(number) print("Callback 2", number) end) + +DisconnectFunction() -- Disconnects the 2nd callback. ``` ### Server @@ -92,9 +95,12 @@ end) Events.PayloadSignalEvent:OnServer(function(Player, number) print("Callback 1 from", Player, number) end) -Events.PayloadSignalEvent:OnServer(function(Player, number) + +local DisconnectFunction = Events.PayloadSignalEvent:OnServer(function(Player, number) print("Callback 2 from", Player, number) end) + +DisconnectFunction() -- Disconnects the 2nd callback. ``` ## Firing Events