Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Elitriare/ByteNet-Max/llms.txt

Use this file to discover all available pages before exploring further.

defineNamespace is the entry point for organizing your ByteNet Max network definitions. It registers a named scope on the server, assigns compact numeric IDs to every packet and query inside it, and replicates those IDs to the client automatically — so both sides always agree on which ID maps to which channel.

Signature

ByteNetMax.defineNamespace(name: string, fn: () -> { packets: {...}, queries: {...} }) -> namespace

Parameters

name
string
required
A unique string identifier for this namespace. The server uses this name to store and replicate the numeric ID mappings to clients. Two namespaces with the same name will collide, so treat it like a primary key.
fn
function
required
A function that returns a table with optional packets and queries keys. Each value must be the result of ByteNetMax.definePacket(...) or ByteNetMax.defineQuery(...). The function is called immediately when defineNamespace runs.

Return value

A table with two sub-tables:
packets
table
A key/value map of every packet defined in the namespace. Each entry is a fully initialized packet object ready to call send, listen, etc.
queries
table
A key/value map of every query defined in the namespace. Each entry is a fully initialized query object ready to call invoke, listen, etc.

Example

The recommended pattern is to place the defineNamespace call inside a ModuleScript and require it on both the server and the client.
-- Shared/Network.luau (ModuleScript)
local ByteNetMax = require(path.to.ByteNetMax)

return ByteNetMax.defineNamespace("PlayerData", function()
    return {
        packets = {
            Notification = ByteNetMax.definePacket({
                value = ByteNetMax.struct({
                    message = ByteNetMax.string,
                    level   = ByteNetMax.uint8,
                }),
            }),
        },
        queries = {
            GetCoins = ByteNetMax.defineQuery({
                request = ByteNetMax.struct({
                    message = ByteNetMax.string,
                }),
                response = ByteNetMax.struct({
                    coins = ByteNetMax.uint8,
                }),
            }),
        },
    }
end)
-- Server Script
local Network = require(path.to.Network)

Network.packets.Notification.listen(function(data, player)
    print(player.Name, "received level", data.level, "notification:", data.message)
end)

Network.queries.GetCoins.listen(function(data, player)
    return { coins = player.leaderstats.Coins.Value }
end)
-- LocalScript
local Network = require(path.to.Network)

Network.packets.Notification.send({ message = "Hello!", level = 1 })

local result = Network.queries.GetCoins.invoke({ message = "How many coins?" })
print("Coins:", result.coins)
The function passed as the second argument is called immediately — ByteNet Max does not defer it. Define all packets and queries inside that function; do not add them to the namespace after defineNamespace returns.
You must require the namespace ModuleScript on both the server and the client. The server generates the numeric IDs; the client reads them. If the client never requires the module, its listeners will never be registered and packets/queries will be silently dropped.

Build docs developers (and LLMs) love