Version: 3.0.9

Scoping with namespaces

As your game grows, so too will your definitions file. To better organize your networking definitions, RbxNet introduces a concept called "Namespaces".

Namespaces are like sub-definitions. They can also be stored in separate files to be included in the main definition file.

Creating a namespace#

Going by our previous example, say we want to separate up inventory and equipment remotes into separate files:

shared/remotes.ts
import Net, { Definitions } from "@rbxts/net";
const Remotes = Net.CreateDefinitions({
// These are all remotes relating to the inventory
Inventory: Definitions.Namespace({
GetPlayerInventory: Definitions.ServerAsyncFunction<() => SerializedPlayerInventory>(),
PlayerInventoryUpdated: Definitions.ServerToClientEvent<[event: InventoryUpdatedEvent]>(),
}),
// These are all the remotes relating to equipping
Equipping: Definitions.Namespace({
GetPlayerEquipped: Definitions.ServerAsyncFunction<() => SerializedPlayerEquipped>(),
PlayerEquippedUpdated: Definitions.ServerToClientEvent<[event: EquippedUpdatedEvent]>(),
PlayerUnequipItem: Definitions.ClientToServerEvent<[itemId: number]>(),
PlayerEquipItem: Definitions.ClientToServerEvent<[itemId: number]>(),
})
});
export = Remotes;

Then simply, if you want to do the same fetch:

Usage from the server#

server/main.server.ts
import Remotes from "shared/remotes";
// This will contain all the server inventory remotes
const InventoryRemotes = Remotes.Server.GetNamespace("Inventory");
// This will contain all the server equipped remotes
const equippedRemotes = Remotes.Server.GetNamespace("Equipped");