Files
Basalt/docs/objects/Timer.md
Robert Jelic bb1b1beb79 Basalt 1.7 Update
- New Objects (Flexbox, Graph, Treeview)
- Pluginsystem to add/remove functionality
- Reworked the entire Object system, instead of one big Object Class we have multiple classes: Object, VisualObject, ChangeableObject
- Instead of one big Frame Class we have multiple Frame Classes: BaseFrame, Frame, MovableFrame, ScrollableFrame, MonitorFrame, Flexbox
- Removed the Animation Object, and added a animation plugin instead
- Removed the Graphic Object and merged it's functionality with the image object
- Updated currently existing objects
2023-04-30 17:05:34 +02:00

1.2 KiB

Timers are objects that allow you to execute code after a specified delay. Unlike Threads, Timers do not use coroutines for concurrency. They are designed to run a function once after the delay has passed.

In addition to the Object methods, Timers have the following methods:

setTime Sets the time the timer should wait before calling your function
start Starts the timer
cancel Cancels the timer

Events

onCall A custom event which gets triggered as soon as the current timer has finished

Example

Here's an example of how to create and use a Timer object:

-- Function that will be executed after the timer delay
local function delayedTask()
  basalt.debug("This message will be displayed after a 5-second delay")
end

-- Create a new Timer object
local main = basalt.createFrame()
local myTimer = main:addTimer()

myTimer:onCall(delayedTask)

-- Set the time delay and start the timer
myTimer:setTime(5)
myTimer:start()

-- Optionally cancel the timer (not needed in this example, as the timer will finish on its own)
-- myTimer:cancel()