API Reference
Module Functions

Module Functions

Top-level functions exposed directly on the KravasNet table.

KravasNet.createNamespace

KravasNet.createNamespace(name: string, initialChannels: {[string]: schema | PacketDef}?): Namespace

Creates a new Namespace — the main container for grouping related channels. Internally maps to exactly one ByteNet.defineNamespace(name, ...) call, deferred until build time.

ParameterTypeRequiredDescription
namestringYesUnique identifier for the namespace. Passed straight through to ByteNet.defineNamespace. Must be unique across your whole game.
initialChannels{[string]: schema | PacketDef}NoChannels to queue immediately. Values can be a raw schema table (defaults to reliable, no middleware) or a KravasNet.packet() definition.

Returns: the new Namespace, with its channels still pending (not yet built).

local CombatNet = KravasNet.createNamespace("Combat", {
	Damage = { amount = KravasNet.float32 },
})
CombatNet:build()

KravasNet.createChannel

KravasNet.createChannel(schema: {[string]: any}, options: ChannelOptions?): Channel

Creates a standalone Channel without attaching it to a user-named namespace. Internally, this generates its own auto-named, immediately-built ByteNet.defineNamespace (named KravasNet_Channel_<n>) so it can register a packet on its own.

ParameterTypeRequiredDescription
schema{[string]: any}YesField-to-type map. Wrapped internally with ByteNet.struct(schema).
optionsChannelOptionsNoSee Middleware & Reliability.

Returns: a ready-to-use Channel — no separate build step needed.

local HealthChannel = KravasNet.createChannel({
	current = KravasNet.uint8,
	max     = KravasNet.uint8,
})
⚠️

Every call to createChannel registers a brand-new anonymous ByteNet namespace. Prefer grouping related channels under one KravasNet.createNamespace() instead of calling createChannel in a loop — each standalone channel has its own network registration overhead.


KravasNet.packet

KravasNet.packet(schema: {[string]: any}, options: ChannelOptions?): PacketDef

Builds a PacketDef — a wrapper bundling a schema together with its ChannelOptions. Used exclusively as a value inside the initialChannels table passed to createNamespace, since plain schema tables there can't carry options on their own.

local CombatNet = KravasNet.createNamespace("Combat", {
	Position = KravasNet.packet({ pos = KravasNet.vec3 }, { reliability = "unreliable" }),
})

KravasNet.ByteNet

KravasNet.ByteNet: ByteNet

Direct reference to the underlying ByteNet module, exposed as an escape hatch for cases the abstraction doesn't cover (e.g. calling ByteNet.defineNamespace yourself for something highly custom).