Skip to main content

Execution Order

The script below will print: 0, A, B, D, C, Start, Finish, Tick, New Tick <0.01666>

printFirst.luau
print("0")
_init.luau
require("./printFirst")
local mod = {}

print("A")

_thread.Create(function(...)
print("B", _thread.Now()) -- B, nil, nil
_thread.Wait(0)
print("C", _thread.Now()) -- C, GameTime, FrameCount
end)

function mod:OnLoad()
print("Start", _thread.Now())
_thread.Create(function()
_thread.Wait(1000)
-- new tick function, we must pass "self" since we use : when calling OnTick
self.OnTick = function(self, deltaTime)
print(`New tick <{deltaTime}>`)
-- stop the tick, again
self.OnTick = nil
end
end)
print("Finish")
end

function mod:OnTick(deltaTime)
print("Tick")
self.OnTick = nil -- stop tick, clear this function from memory
end

print("D")

return mod