diff --git a/README.md b/README.md index 21db3cd..899ee2f 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Contents: ------------ * *gamestate.lua*: Easy gamestate management. -* *timer.lua*: Delayed and time-limited function calls. +* *timer.lua*: Delayed and time-limited function calls and tweening functionality. * *vector.lua*: 2D vector math. * *vector-light.lua*: Lightweight 2D vector math (for optimisation purposes - leads to potentially ugly code). * *class.lua*: Lightweight object orientation (class or prototype based). diff --git a/timer.lua b/timer.lua index 87ec3db..7cb8ff6 100644 --- a/timer.lua +++ b/timer.lua @@ -60,15 +60,16 @@ function Timer:add(delay, func) end function Timer:addPeriodic(delay, func, count) - local count = count or math.huge -- exploit below: math.huge - 1 = math.huge + local count, handle = count or math.huge -- exploit below: math.huge - 1 = math.huge - return self:add(delay, function(f) + handle = self:add(delay, function(f) if func(func) == false then return end count = count - 1 if count > 0 then - self:add(delay, f) + self.functions[handle] = delay end end) + return handle end function Timer:cancel(handle)