Hello everybody.
Sorry if this turns out to be a silly question.
In a function in my script, I say
local a = timer.delay(5, true, function ()
--after some time
timer.cancel(a)
end)
It throws an error saying that bad argument to timer.cancel(), number expected, got nil.
Where am I going wrong??
Thanks in advance.
dmitriy
2
a is undefined here. Actually, this is different global undefined variable, not your “a”.
Do this instead:
local a
a = timer.delay(5, true, function ()
--after some time
timer.cancel(a)
end)
5 Likes
britzl
3
Another option:
timer.delay(5, true, function(self, handle, time_elapsed)
timer.cancel(handle)
end)
3 Likes
Thanks @dmitriy and @britzl, finally I understood how to use timer!
1 Like