Skip to main content

Broadcaster

Watches an Agent on the server and produces what a client Replica consumes: state changes, pivot position samples at a rate, and emitted events. Make it before agent:Start() so the initial state is relayed; nothing emitted before it existed is replayed. Wire its signals to your remotes:

local broadcaster = VluxyAI.Sync.Broadcaster.new(agent)
broadcaster.StateChanged:Connect(function(state)
	syncRemote:FireAllClients({ Kind = "State", Id = id, State = state })
end)
broadcaster.EventSent:Connect(function(name, payload)
	syncRemote:FireAllClients({ Kind = "Event", Id = id, Name = name, Payload = payload })
end)

Snapshot gives a late joiner everything at once.

Types​

Broadcaster​

interface Broadcaster {
StateChanged: Signal<(
string,
string?
)>--

Relayed from the agent.

PositionChanged: Signal<(
number
)>--

The rig's pivot position and yaw, at PositionRate.

EventSent: Signal<(
string,
any
)>--

Relayed from agent.Events.

Step: (
self: Broadcaster,
deltaTime: number
) → ()
Snapshot: (self: Broadcaster) → Snapshot
Destroy: (self: Broadcaster) → ()
}

What new returns.

Functions​

new​

Broadcaster.new(
agent: Agent,
) → Broadcaster

Types

​

interface BroadcasterOptions {
PositionRate: number?--

Position samples per second. 0 sends none. Default 10.

MoveEpsilon: number?--

Studs the rig must move to be worth a sample. Default 0.05.

TurnEpsilon: number?--

Radians the rig must turn to be worth a sample. Default 0.01.

}

Step​

Broadcaster.Step(
self: BroadcasterClass,
deltaTime: number
) → ()

One frame of the position sampler. Driven by Heartbeat; a test calls it directly.

Snapshot​

Broadcaster.Snapshot(self: BroadcasterClass) → Snapshot--

The current state, position and yaw, for a client that just joined.

Destroy​

Broadcaster.Destroy(self: BroadcasterClass) → ()

Disconnects from the agent. Happens on its own when the agent is destroyed.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "",
            "params": [
                {
                    "name": "agent",
                    "desc": "",
                    "lua_type": "Agent"
                },
                {
                    "name": "options",
                    "desc": "",
                    "lua_type": "BroadcasterOptions?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Broadcaster"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 137,
                "path": "lib/Sync/Broadcaster.luau"
            }
        },
        {
            "name": "Step",
            "desc": "One frame of the position sampler. Driven by Heartbeat; a test calls it directly.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "BroadcasterClass"
                },
                {
                    "name": "deltaTime",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 188,
                "path": "lib/Sync/Broadcaster.luau"
            }
        },
        {
            "name": "Snapshot",
            "desc": "",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "BroadcasterClass"
                }
            ],
            "returns": [
                {
                    "desc": "The current state, position and yaw, for a client that just joined.",
                    "lua_type": "Snapshot"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 227,
                "path": "lib/Sync/Broadcaster.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Disconnects from the agent. Happens on its own when the agent is destroyed.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "BroadcasterClass"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 241,
                "path": "lib/Sync/Broadcaster.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "BroadcasterOptions",
            "desc": "",
            "fields": [
                {
                    "name": "PositionRate",
                    "lua_type": "number?",
                    "desc": "Position samples per second. `0` sends none. Default `10`."
                },
                {
                    "name": "MoveEpsilon",
                    "lua_type": "number?",
                    "desc": "Studs the rig must move to be worth a sample. Default `0.05`."
                },
                {
                    "name": "TurnEpsilon",
                    "lua_type": "number?",
                    "desc": "Radians the rig must turn to be worth a sample. Default `0.01`."
                }
            ],
            "source": {
                "line": 38,
                "path": "lib/Sync/Broadcaster.luau"
            }
        },
        {
            "name": "Broadcaster",
            "desc": "What `new` returns.",
            "fields": [
                {
                    "name": "StateChanged",
                    "lua_type": "Signal<(string, string?)>",
                    "desc": "Relayed from the agent."
                },
                {
                    "name": "PositionChanged",
                    "lua_type": "Signal<(Vector3, number)>",
                    "desc": "The rig's pivot position and yaw, at `PositionRate`."
                },
                {
                    "name": "EventSent",
                    "lua_type": "Signal<(string, any)>",
                    "desc": "Relayed from `agent.Events`."
                },
                {
                    "name": "Step",
                    "lua_type": "(self: Broadcaster, deltaTime: number) -> ()",
                    "desc": ""
                },
                {
                    "name": "Snapshot",
                    "lua_type": "(self: Broadcaster) -> Snapshot",
                    "desc": ""
                },
                {
                    "name": "Destroy",
                    "lua_type": "(self: Broadcaster) -> ()",
                    "desc": ""
                }
            ],
            "source": {
                "line": 81,
                "path": "lib/Sync/Broadcaster.luau"
            }
        }
    ],
    "name": "Broadcaster",
    "desc": "Watches an [Agent] on the server and produces what a client [Replica] consumes: state\nchanges, pivot position samples at a rate, and emitted events. Make it before `agent:Start()`\nso the initial state is relayed; nothing emitted before it existed is replayed. Wire its\nsignals to your remotes:\n\n```lua\nlocal broadcaster = VluxyAI.Sync.Broadcaster.new(agent)\nbroadcaster.StateChanged:Connect(function(state)\n\tsyncRemote:FireAllClients({ Kind = \"State\", Id = id, State = state })\nend)\nbroadcaster.EventSent:Connect(function(name, payload)\n\tsyncRemote:FireAllClients({ Kind = \"Event\", Id = id, Name = name, Payload = payload })\nend)\n```\n\n`Snapshot` gives a late joiner everything at once.",
    "source": {
        "line": 130,
        "path": "lib/Sync/Broadcaster.luau"
    }
}