Hey everyone. I was looking around and no one seemed to have an answer for this. I’m trying to make a program that counts how many times I tap the screen, but I always get error messages when I try to use it.
Here’s the code
function setup()
touch={}
end
function touched(touch)
touch[touch.tapCount] = touched
print(touch.tapCount)
end
function draw()
for k,touch in pairs(touch)do
end
ellipse(400,400,40)
end
you need to rename your variables so they don’t interfere with each other
you need to increment the variable, not just reset it every touch.
Here’s an example:
function setup()
touchCount = 0 -- Name your variable something relevant that doesn't conflict with others
end
function touched(touch)
if touch.state == BEGAN then -- Do this only once every time you touch the screen
touchCount = touchCount + 1 -- Increment your value (add one to what it already was)
end
end