Skip to content
Caffeine Docs

Ticker

Caffeine has a dynamic Ticker system that will automatically adjust the tick rate. The tick rate will default to 2x the current frame rate.

So if you are getting 60 fps, the framerate will be .03

You can also set the offset to the tickrate in the Caffeine configuration. Note that regardless of what you set it to, the framerate will never be lower than 0.01.

This means that if you are getting 100 FPS (.01), and you set it to + 100 ms in the Caffeine interface, the configured tickrate will be (0.11). If you are getting 100 FPS (.01) and you set the offset to -100 ms in the Caffeine interface, the configured tickrate will be (.00). since this is below the floor of .01, the tickrate will be .01.

Caffeine.Ticker

The following are the available Methods within the Timer module:

Schedule Timer

function Ticker:ScheduleTimer(func, delay, repeating, timerType, ...)

arguements

func (mandatory)

The function to be called when timer expires

delay (mandatory)

The amount of time to wait before firing or interval between firings for repeting timers

repeating (not mandatory)

boolean to indicate whetheer the timer should repeat

timerType (not mandatory)

indicates when the timer should be active:

1 or "normal" = when caffeine is enabled 
2 or "always" = all times, even when caffeine is not enabled
3 or "onUpdate" = every frame (drawings)

ScheduleEnabledTimer(func, delay, …)

function Ticker:ScheduleEnabledTimer(func, delay, ...)
	-- will only fire when Caffeine is enabled
	return Ticker:ScheduleTimer(func, delay, true, 1, ...)
end

ScheduleOnUpdateTimer(func, …)

function Ticker:ScheduleOnUpdateTimer(func, ...)
	-- will fire every frame
	return Ticker:ScheduleTimer(func, 0, true, 3, ...)
end

ScheduleAlwaysTimer(func, delay, …)

function Ticker:ScheduleAlwaysTimer(func, delay, ...)
	-- will fire even when Caffeine is disabled
	return Ticker:ScheduleTimer(func, delay, true, 2, ...)
end

ScheduleOneTimeEnabledTimer(func, delay, …)

function Ticker:ScheduleOneTimeEnabledTimer(func, delay, ...)
	-- will fire once when Caffeine is enabled
	return Ticker:ScheduleTimer(func, delay, false, 1, ...)
end

ScheduleOneTimeAlwaysTimer(func, delay, …)

function Ticker:ScheduleOneTimeAlwaysTimer(func, delay, ...)
	-- will fire once even when Caffeine is disabled
	return Ticker:ScheduleTimer(func, delay, false, 2, ...)
end

ScheduleOneTimeOnUpdateTimer(func, …)

function Ticker:ScheduleOneTimeOnUpdateTimer(func, ...)
	-- will fire once next frame
	return Ticker:ScheduleTimer(func, 0, false, 3, ...)
end

### CancelTimer


```lua
Caffeine.Timer:CancelTimer(Caffeine.timers.RefreshObjectManager)

TimeLeft

local timeLeft = Caffeine.Timer:TimeLeft(Caffeine.timers.RefreshObjectManager)