Over the past two days I’ve been working on a module that’d make communication simple and easy, so I’ve come up with Cucumber. The module’s syntax is easy to work with, (though, something to note, I was quite lazy to add type-checking so studio may not show you all the methods and properties) and versatile.
The module can be found here: Cucumber
To create a connection, simply do:
local Connection = Cucumber.Connection('TestCase') --> connectionName should be unique if you do not want to get the same connection object
(This works on both client and server implementations, we will assume the connection is on the server for the next snippet)
And then to detect for when Connection has been fired, simply :Connect()
to the Connection, like so:
Connection:Connect(function(player : Player, ...) --> server has first arg as player always.
print('Hello from Client!')
end)
To fire our connection, you need to create a new Bridge
instance with the same name as the connection from the client, if the connection is on the server, or from the server, if the connection is on the client.
local Bridge = Cucumber.Bridge('TestCase')
And, to fire our bridge, you’d do:
Bridge:Fire(...)
which returns nothing, and does not yield. If you’ve properly set this up, you should now see the server printing: '‘Hello from Client!’ (please note that any fires for a bridge’s name that does not have a connection set-up nor a receiver (via :Connect or other methods) will be lingering until one is added)
Some other useful functions of this module are ports, ports are special connections which act like remotefunctions, where the returns of the connections are replicated to the client, this can be used like the following
-- Server
local Connection = Cucumber.Connection('GetStatus')
Connection:OpenPort('GET'):Connect(function(player)
return 'Online'
end, 'Status') --:Connect(() -> (...any), resolveName : string?)
-- Client
local Bridge = Cucumber.Bridge('GetStatus')
print(Bridge:FirePort('GET')) --> this function will yield, the output should look like this:
--[[
{
Status = 'Online',
}
(single variable returns / non-tuple returns will be automatically cast into one value, otherwise it'd look something more like Status = {'Online', 'Ingame'} with return 'Online', 'Ingame'.
]]--
this can also be done vice-versa (Server → Client), but note that FirePort needs 2nd argument as Player for this, and it may be insecure due to exploiters yielding forever.
I hope my first tutorial and my first community resource I have every written, please report any bugs, I will try to maintain this module as much as motivation lets me