Skip to content

Timers and utilities

Timers

Balltze.setTimer

local timer = Balltze.setTimer(interval, callback)

Calls callback repeatedly, every interval milliseconds. Timers are checked at the end of every frame, so they can run late by up to one frame. They are removed when the plugin unloads.

Returns a Timer with a stop() function. Calling stop() a second time raises an error.

local seconds = 0
local timer
timer = Balltze.setTimer(1000, function()
    seconds = seconds + 1
    if seconds == 10 then
        timer.stop()
    end
end)

Note

Timers depend on frames, so they do not run on the dedicated server, which draws nothing. Count ticks with the tick event there instead: there are 30 ticks per second.

Timestamps

Balltze.createTimestamp

local timestamp = Balltze.createTimestamp()

Returns a BalltzeTimestamp that measures the time passed since it was created.

Method Returns Description
getElapsedMilliseconds() integer Milliseconds since it was created or reset.
getElapsedSeconds() integer Seconds since it was created or reset.
reset() Starts counting again from now.

Clipboard

Balltze.getClipboard

local text = Balltze.getClipboard()

Returns the text in the Windows clipboard.

Balltze.setClipboard

Balltze.setClipboard(text)

Puts text in the Windows clipboard.