mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
fix(timer): redefine local function as method
The previous commit added a private property, but they cannot be set outside of class methods. Added an error when starting a running timer, too.
This commit is contained in:
@@ -35,27 +35,28 @@ function timer:constructor(time, onEnd, async)
|
|||||||
self:start(async)
|
self:start(async)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@protected
|
||||||
|
function timer:run()
|
||||||
|
while self:isPaused() or self:getTimeLeft('ms') > 0 do
|
||||||
|
Wait(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.private.triggerOnEnd then
|
||||||
|
self:onEnd()
|
||||||
|
end
|
||||||
|
|
||||||
|
self.private.triggerOnEnd = true
|
||||||
|
end
|
||||||
|
|
||||||
function timer:start(async)
|
function timer:start(async)
|
||||||
if self.private.startTime > 0 then return end
|
if self.private.startTime > 0 then error('Cannot start a timer that is already running') end
|
||||||
|
|
||||||
self.private.startTime = GetGameTimer()
|
self.private.startTime = GetGameTimer()
|
||||||
|
|
||||||
local function tick()
|
if not async then return self:run() end
|
||||||
while self:isPaused() or self:getTimeLeft('ms') > 0 do
|
|
||||||
Wait(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.private.triggerOnEnd then
|
|
||||||
self:onEnd()
|
|
||||||
end
|
|
||||||
|
|
||||||
self.private.triggerOnEnd = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if not async then return tick() end
|
|
||||||
|
|
||||||
Citizen.CreateThreadNow(function()
|
Citizen.CreateThreadNow(function()
|
||||||
tick()
|
self:run()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user