mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56: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)
|
||||
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)
|
||||
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()
|
||||
|
||||
local function tick()
|
||||
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
|
||||
if not async then return self:run() end
|
||||
|
||||
Citizen.CreateThreadNow(function()
|
||||
tick()
|
||||
self:run()
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user