Skip to content

Containers

Containers are the recommended and easy way to group together messages in light by name.

Container inputs should be a map of string message-names to any valid Datatype. This includes Datatypes like arrays or maps that are defined with luau tables. I.e., { light.datatypes.u8 }

If messages inside are already synchronized beforehand, the container will not yield.

The server defines the messages immediately, so container {...} will never yield on the server.

function light.container (On The Client)

Shared Synchronous Yielding
1
2
3
4
function container<MessageNames>(
    message_names: MessageNames, -- { [string]: Datatype }
    namespace: string? --(1)!
): (MessageNames)

function light.container (On The Server)

Shared Synchronous
1
2
3
4
function container<T>(
    message_names: T, -- { [string]: Datatype }
    namespace: string?
): (T)

Namespaces don't impact behavior

Namespaces do not impact message ordering whatsoever in light. They are entirely cosmetic, allowing you to have multiple containers with overlapping message names.

Some example code using containers:

1
2
3
4
5
6
7
local light = require(ReplicatedStorage.light).shared

local ty = light.datatypes

return light.container({
    abc = { ty.u8 }, -- send a table of u8 numbers
}, "some-cool-namespace")

You can replicate the above code 1:1 with light.message()