diff --git a/init.lua b/init.lua index dd19c0e..d39a354 100644 --- a/init.lua +++ b/init.lua @@ -35,6 +35,37 @@ function import(file) return IMPORTS[file] end +----------------------------------------------------------------------------------------------- +-- Global functions +----------------------------------------------------------------------------------------------- + +--- Dream of a world where this PR gets accepted. +--- ```lua +--- SetInterval(callback: function, timer: number) +--- ``` +SetInterval = setmetatable({currentId = 0}, { + __call = function(self, callback, timer) + local id = self.currentId + 1 + self.currentId = id + self[id] = timer or 0 + CreateThread(function() + repeat + local interval = self[id] + Wait(interval) + callback(interval) + until interval == -1 + self[id] = nil + end) + return id + end +}) + +function ClearInterval(id) + if SetInterval[id] then + SetInterval[id] = -1 + end +end + -- pe-lualib -- Copyright (C) 2021 Linden