function myRecursiveFunction(time, ...)
print(...)
addEvent(myRecursiveFunction, time, time, ...)
end
myRecursiveFunction(2 * 1000 * 60, "this function will execute every 2 minutes forever or until you shutdown the server ;)")
local h = os.time()
local last = h
local int = 60*60*1 -- in seconds
local advertisement = math.random(1, 10)
function onThink(interval, lastExecution)
if (last + int) < h then
last = h
if advertisement == 1 then
broadcastMessage("testing", MESSAGE_EVENT_ADVANCE)
advertisement = 2
elseif advertisement == 2 then
broadcastMessage("testing", MESSAGE_EVENT_ADVANCE)
advertisement = 1
end
-- keep putting the two to test
end
h = os.time()
return true
end
<globalevent name="script" interval="" event="script" value="script.lua"/>
50 milliseconds
#define SCHEDULER_MINTICKS 50
interval="50"
function addEvent(f, t, ...)
local nTime = os.time() + t
repeat until os.time() >= nTime
return f(...)
end
addEvent(print, 3, "This is a test")
This is a test
Program completed in 3.21 seconds (pid: 4077).
addEvent(callback, delay, ...)
uint32_t delay = std::max<uint32_t>(100, getNumber<uint32_t>(globalState, 2));
the interval per default of the functionis 100 milliseconds.Code:addEvent(callback, delay, ...)
It would be much better if you told us what you want to do with this?Code:uint32_t delay = std::max<uint32_t>(100, getNumber<uint32_t>(globalState, 2));