Hooks
Hooks allow you full control of scheduling logic, allowing YetAnotherNet to be used for any game structure whether ECS or not.
When you use createHook
, it will return a beginFrame
and endFrame
function which should be called at the beginning and end of each frame respectively.
It's expected, and recommended that you still run your scheduling code on RunService.Heartbeat
, otherwise you may run into unexpected behavior. If you know
what you're doing, you can ignore this warning.
- Luau
- Typescript
local RunService = game:GetService("RunService")
local YetAnotherNet = require("@packages/YetAnotherNet")
local routes = require("@shared/routes")
local myRoute = routes.myRoute
local beginFrame, endFrame = YetAnotherNet.createHook({ Route })
RunService.Heartbeat:Connect(function()
beginFrame()
myRoute:send(...)
for i, player, data in myRoute:query() do
-- Do something
end
endFrame()
end)
import { RunService } from "@rbxts/services";
import Net from "@rbxts/yetanothernet";
import routes from "shared/routes";
const myRoute = routes.myRoute;
const beginFrame, endFrame = Net.createHook(routes);
RunService.Heartbeat.Connect(() => {
beginFrame();
myRoute.send(...)
for (const [pos, sender, ...] of myRoute.query()) {
// Do something
}
endFrame();
});