How to create a timer on a button?

I have a 2 buttons, one moves a ship left a lane, one moves it right a lane. But I am trying to get it so as if the player holds the button down, it will increase a lane every 0.1 seconds.

At the moment it just increases 1 lane, no matter how long it is held for. I still want it to move just one if the button is released quickly, but if held I would like it to increase until released.

my code is below,

local buttonHandler = function( event )
if event.phase == “press” then
if event.id == “stop” then
lane = 1
elseif event.id == “+1” then
lane = lane + 1
elseif event.id == “-1” then
lane = lane -1

Can anybody help? Sorry if I don’t reply straight away, its late and Im off to bed!

thanks [import]uid: 8699 topic_id: 5178 reply_id: 305178[/import]

you want to set a flag in your touch event “began” phase eg

[lua]direction=-1[/lua]

and then start an infinite timer that adds the direction to the object

eg

[lua]obj.x = obj.x + direction[/lua]

in your “ended” or “cancelled” phase, cancel the timer
[import]uid: 6645 topic_id: 5178 reply_id: 17190[/import]

thanks, got it working! [import]uid: 8699 topic_id: 5178 reply_id: 17300[/import]