Networking
Networking is a built in feature of comet, allowing you to seamlessly define type-safe bindable events and functions for use anywhere in your plugin.
Usage
Typically, it's best to create a network.ts
file in the root of your project.
Functions and events can be defined like so:
src/network.ts
import { Networking } from "@rbxts/comet"
export default {
sayHello: Networking.Event<[message: string]>(),
requestGreeting: Networking.Function<[message: string], string>()
}
And to use them, you can simply import the network
system we created wherever you'd like.
src/systems/mySystem.ts
//...
// Events
network.sayHello.connect((message: string) => print(message));
network.sayHello.fire("Hello!");
// Functions
network.requestHello.callback(async (name) => `Hello, ${name}!`);
network.requestHello.invoke("Neohertz").then((res) => {
print(res); // "Hello, Neohertz!"
});
//...