Version: 2.1.5
Creating a definition
In RbxNet, there are three categories of remote objects:
- Event - This is analogous to a
RemoteEvent
. This is what is used if you want to send an event (like an action) to the server or a player. - AsyncFunction - This is like a
RemoteFunction
, but usesRemoteEvent
internally. The difference with this andFunction
is thatAsyncFunction
will handle time outs and runs completely asynchronously. (meaning it wont yield code) If there is no response from the reciever, it will reject. - Function - This is analogous to a
RemoteFunction
. However unlike a regularRemoteFunction
this does not allow you to call a client. This is for security reasons discussed here
#
Defining Events & FunctionsGiven the above knowledge, we can then apply that to our remote definition script. There are the following functions under Net.Definitions
for creating definitions for the three categories we have above. The API for each type of definition is explicit so it is easy to understand what each defined remote does.
#
The different types of definitionsEvent
Net.Definitions.ServerToClientEvent
- Defines an event in which the server sends an event to one or many clientsNet.Definitions.ClientToServerEvent
- Defines an event in which the client send events to the serverNet.Definitions.BidirectionalEvent
- Defines an event in which both the server can send an event to one or many clients, and also the clients can send events to the server. This should only be used in cases where it's required.
AsyncFunction
Net.Definitions.ServerAsyncFunction
- Defines an async function which exists on the server, and can be called by clients. The returned result will be recieved on the client as a promise.Net.Definitions.ClientAsyncFunction
- Defines an async function which exists on the client, and can be called by the server. The returned result will be recieved on the server as a promise.
Function
Net.Definitions.ServerFunction
- Defines a synchronous function which exists on the server, and can be called by clients
#
Defining remotesWith the above knowledge, we can create a few example definitions. Say I would like a use case like the following
- roblox-ts
- luau
shared/remotes.ts
src/shared/remotes.lua
Straight away you can see it's quite easy to know what remote does what.