Timer

Hi,

I’m coming from a Javascript/flash background and I’m getting confused :S

Basically, I want to run a function every second or so.

Inside an enterFrame, I have this:

[blockcode]
lapsedTime=system.getTimer()-startTime
counter = lapsedTime / 100

if(counter > 3) then
–function goes here
counter = 0
end
[/blockcode]

So, I thought that the the timer would count up to three, then reset to zero and start counting again. Instead, it just stops at zero. Any ideas? Am I going about this the wrong way?

Thanks.
[import]uid: 35072 topic_id: 6254 reply_id: 306254[/import]

Have a look at Timer:
http://developer.anscamobile.com/content/timer-library

For example:
[lua] local t = {}
function t:timer( event )
local count = event.count
print( “Table listener called " … count … " time(s)” )
if count >= 3 then
timer.cancel( event.source ) – after 3rd invocation, cancel timer
end
end

– Register to call t’s timer method an infinite number of times
timer.performWithDelay( 1000, t, 0 )[/lua] [import]uid: 8045 topic_id: 6254 reply_id: 21872[/import]