CurrentTouch.state == Click

Hello again,
I’ve a little problem with Codea. It’s about one time touch and double times click.
Here is a sample code:


function setup()
   watch("numberTap")
   numberTap = 0
end

function addTap()
   numberTap = numberTap + 1
end 

function draw()
   if CurrentTouch.state == BEGAN
      addTap()
   end
end

When I tap on the screen the variable numberTap is updated continuously not one time.
I think that the solution is:


if CurrentTouch.state == ClickPressed
      addTap()
   end

So, I suggest you to add: ClickPressed and ClickReleased.
I hope you understand my problem.

Edit: I do not know how to put this code here: don’t works. You know the codes for this forum?

The way I’ve been dealing with this is to keep track of touch state.<br

In setup, add a global oldState = nil

Then in your check loop do

if (CurrentTouch.state == BEGAN and oldState ~= CurrentTouch.state)

addTap()

end

Check for this instead


if CurrentTouch.state == ENDED and CurrentTouch.tapCount == 2 then
    performAction()
end

Mark, don’t works. Please give me an full example about One Simple Click.
Simeon, Your example works fine, but not works fine for One Simple Click and I know why, because function draw is updated every one frame, maybe, Here we need a function that is not automatically updated every frame, only if it interacted with touch event.

Does this help?

https://bitbucket.org/TwoLivesLeft/codea/wiki/TouchTutorial

function touched(touch) is the separate way to handle touches you are looks for I think.

@Georgian: @Ipda41001 is correct, use the touched(touch) callback to handle touch events only when they occur and not every frame.

The state / oldState solution works, but you need to add oldState = CurrentTouch.state after the addTap() call.

Sorry I left that out

Many thanks to Ipda41001, HURRAY! it works! Sorry for this inconvenience, I will consult the Codea Documentation & Wiki.