os commands are disabled in toribash, try using get_world_state().frame_tick (then multiply delay by 1000 as it's in milliseconds)
Here's a basic timer class if you wanted an example:
Timer = { }
Timer.__index = Timer
Timer.Count = 0
function Timer.New(Time, Recurring,Function)
Timer.Count = Timer.Count + 1
sT = get_world_state().frame_tick
local timer = { }
setmetatable(timer,Timer)
timer.Time = Time+sT
timer.N = Timer.Count
if(Recurring) then
timer.Interval = Time
else
timer.Interval = -1
end
timer.Function = Function
add_hook("draw2d","timer "..Timer.Count,function() timer:Tick() end)
return timer
end
function Timer:Tick()
local sT = get_world_state().frame_tick
if(self.Time <= sT) then
self.Function()
if(self.Interval ~= -1) then
self.Time = get_world_state().frame_tick+self.Interval
else
self:Dispose() --Dispose.
end
end
end
function Timer:Dispose()
remove_hook("draw2d","timer "..self.N)
self = {}
end
example:
A = Timer.New(1000,0,new function() echo("Moo") end)
i = 0
B = Timer.New(2000,1,new function() echo("Ticked: " .. i); i = i + 1 end)
Last edited by Blam; Aug 31, 2009 at 11:31 PM.