I’ve been implementing this module into my game but I came across an issue. There doesn’t seem to be a way to disconnect any OnClientEvent/OnServerEvent event connections when using the BindEvents method. Do you think you could update the module to add a way to do this?
I noticed this module doesn’t have an API for BindableEvents. Does your game not utilize Server to Server communication? How would you go about this if needed? Would you just implement them the standard way?
Typically I have server modules communicate with each other just by requiring each other and calling public methods, with a little setmetatable trick to eliminate the stack overflow problem of circular dependencies. BindableEvents also work though, but I typically just use that if I’m wanting to listen for a specific event.
I didn’t include that kind of stuff in this module since it’s easy enough to add on your own and isn’t really relevant to what this module is for
little setmetatable trick? mind enlightening us?
Does it clean out event connections to prevent memory leaks?
Hi there~ @tyridge77
Thank you for sharing your creation with us, this is very interesting stuff.
Does this not support :BindFunctions on the client?
Nothing against this, but how much performance would this take away if I was doing a bunch of different remotes?
Because if it is creating them, it is using a small amount of processing power to replicate them.
Really cool module, was super simple to implement into my workflow!
Only thing I noticed though was that there’s no out-of-the box support for Events that are only ‘Server=>Client’ and don’t have a Server-Sided Callback.
I was able to add support super easily thanks to the cleanliness of your code, but it would still be cool to see methods like “CreateEvents” & “CreateFunctions” for those events/functions that don’t require OnServerEvent/OnServerInvoke connections and are only intended to be used with FireClient/InvokeClient.
Sorry if this has already been fixed and I’m on an outdated version.
I had this error occur to me on one of my clients in-game:
ReplicatedStorage.MyGame.Network:593: invalid argument #1 to 'char' (invalid value) ReplicatedStorage.MyGame.Network, line 593 - function ToByteString ReplicatedStorage.MyGame.Network, line 645 - function InvokeServer
I found the root cause (pic below)
It looks like ResponseCounter
is used to basically created a pseudo-unique id for tracking responses from the client, to the server, and it is only allowed to increment up, with a rolling modulo on 2^32
to presumably keep it in check from having an integer overflow and going into negative numbers.
Somehow one of my clients got a negative integer going into ToByteString
. I assume either 2 ^32
rolled over into a negative int or ResponseCounter
did. I’ve re-written the logic to something a little simpler to hopefully prevent this, won’t know for a few weeks of 0 issues, though.
Updated with some improvements/fixes (i.e fixed issue where order of remotes was lost if they arrive before event is bound) and also added some new methods
Seems super cool and might be using this! Will this also have a way to implement debounce to events or we will have to do this.
I am leaving a post so I can come back to this tomorrow morning.
I’ll definitely take a look into this piece of art.
I had an idea to add onto EasyNetwork, could do it on my own code but thought it would be nice to have in the main “branch” of it -
The ability to do server → server events through the API. Right now you can only do Server → Client or Client → Server.
It’d be nice to have the same easy API if I wanted to do a Server → Server pattern
The API actually wouldn’t change, still use Network:FireServer() and Network:InvokeServer(), just look at registered Client events first, if not found there, look at events setup using Network:BindFunctions() from the server. And if there’s a duplicate name used in Client/Server you could maybe throw a warning to let the dev know.
Not sure if you are aware of this, if you aren’t, with deferred events enabled, calling any remotes via the module causes a script timeout exception. It seems that the SafeFireEvent function causes this error.
--Deferred events are on
--Line 226
FastSpawn(function(...) --Stack Trace points to this line raising the error
--assuming this below while loop is the cause
while running and index > 0 do
local fn = callbacks[index]
index -= 1
fn(...)
end
end, ...)
running = false
end
end
I am not sure of any solutions for the error at this time, but if I do figure out something, I’ll edit this post with a fix
Is this compatible with BindableEvents?
Is this available on Roblox-TS?
no, also use a signal module bindable events are disgusting
local Signal = {}
Signal.__index = Signal
local Connection = {}
Connection.__index = Connection
function Signal.New()
return setmetatable({
Connections = {};
Yields = {};
}, Signal)
end
function Signal:Fire(...)
for _, v in ipairs(self.Connections) do
coroutine.wrap(v.func)(...)
end
for k, v in ipairs(self.Yields) do
coroutine.resume(v, ...)
table.remove(self.Yields, k)
end
end
function Signal:Connect(func)
local connection = setmetatable({
func = func;
orgSelf = self;
}, Connection)
table.insert(self.Connections, connection)
return connection
end
function Signal:Wait()
table.insert(self.Yields, coroutine.running())
return coroutine.yield()
end
function Connection:Disconnect()
for k, v in ipairs(self.orgSelf.Connections) do
if v == self then
table.remove(self.orgSelf.Connections, k)
end
end
setmetatable(self, nil)
end
function Signal:Destroy()
for _, v in ipairs(self.Connections) do
v:Disconnect()
end
for _, v in ipairs(self.Yields) do
coroutine.resume(v)
end
setmetatable(self, nil)
end
Hi,
I have copied the Server & Client examples but then I run I get the error below in the client script, I have the network module in ReplicatedStorage I used game:GetService(“InsertService”):LoadAsset(5023179796):GetChildren()[1].Parent = game.ReplicatedStorage
BindEvents is not a valid member of ModuleScript “ReplicatedStorage.Network” - Client - NetworkTest-LS:5
Thanks
You need to require() the module