Lifecycle Events
Lifecycle events are a crucial component for most singletons, because they allow your singleton to react to certain events. The most common one is the start
lifecycle event which gets fired as the singleton starts.
Available Lifecycle Events
Identifier
Description
Platform
start
Fires once when the singleton starts
Client + Server
stop
Fires once before the server shuts down. Yielding here will halt the thread
Server
onTick(dt: number)
Is directly hooked to RunService.Heartbeat
runs after physics are done
Client + Server
onPhysics(t: number, dt: number)
Is directly hooked to RunService.Stepped
and runs prior to physics
Client + Server
onRender(dt: number)
Is directly hooked to RunService.RenderStepped
Client
Using Lifecycle Events
You can use lifecycle events by explicitly defining them in your singleton:
local Service = Quebec.singleton({
lifecycles = {
"start", -- regular lifecycle
["onPhysics"] = "doPhysicsStuff", -- remap the lifecycle to a different method
}
})
function Service:start()
print("started")
end
-- remember, normally it's "onPhysics", but we remapped it
function Service:doPhysicsStuff(t: number, dt: number)
print("physics")
end
return Service
Last updated