TIP: fire first call immediately in timer.performWithDelay

where there’s a will there’s a way!

say you want an action to repeat every 5 seconds, but you want the first one to happen straight away… you can do this:

[lua]local myTimer = timer.performWithDelay(0, doSomething, -1)

– set delay for further calls after the first
myTimer._delay=5000[/lua]

[import]uid: 6645 topic_id: 3825 reply_id: 303825[/import]

i double checked this with something simple to check the first one didnt fire a couple of times before the delay could be set

[lua]local function doSomething(event)

print(event.count…":"…os.date())

end

local myTimer = timer.performWithDelay(0, doSomething,-1)
myTimer._delay = 5000[/lua]

output
[lua]1:Sat Nov 20 16:00:55 2010 – called immediately
2:Sat Nov 20 16:01:00 2010
3:Sat Nov 20 16:01:05 2010
4:Sat Nov 20 16:01:10 2010
5:Sat Nov 20 16:01:15 2010
6:Sat Nov 20 16:01:20 2010[/lua] [import]uid: 6645 topic_id: 3825 reply_id: 11624[/import]