retrieve a letter from a table only once

hello i’m a new in corona sdk and i have a problem 

i have a table with 5 boxes, in these boxes there is a letter and i want to retrieve this letter once ,

for example : S D K

the S is between 0 and 100 in x and between 0 - 100 in y 

the D is between 100 and 200 in x and between 0 - 100 in y

etc… K 200-300(x) and 0-100(y)

these are coordinate on the screen

when i move my finger on the screen i want to display(on the console) the letter once and i don’t know how to do

local function mytouchlistener(event)

local ex = event.x

local ey = event.y

if (ex >= 0 and ex <= 100 and ey >= 0 and ey <=100) then

print(“S”)

end 

if (ex >= 100 and ex <= 200 and ey >= 0 and ey <=100) then

print(“D”)

end 

if (ex >= 200 and ex <= 300 and ey >= 0 and ey <=100) then

print(“K”)

end 

do return true end

return true

end

Runtime:addEventListener("touch, mytouchlistener)

when i move my finger on the screen it display 100 times the letter 

can somemone help me plz?

Each event has a phase. 

The phase can be “began”, “moved”, “ended” or “cancelled”.

If you want to trigger the event when the user starts touching the area use event.phase == “began”

If you want to trigger the event when the user releases the area use event.phase == “ended”

Just nest an extra if statement before you start testing the coordinates, and you’ll be fine :slight_smile:

Reference:

http://docs.coronalabs.com/api/event/touch/phase.html

Each event has a phase. 

The phase can be “began”, “moved”, “ended” or “cancelled”.

If you want to trigger the event when the user starts touching the area use event.phase == “began”

If you want to trigger the event when the user releases the area use event.phase == “ended”

Just nest an extra if statement before you start testing the coordinates, and you’ll be fine :slight_smile:

Reference:

http://docs.coronalabs.com/api/event/touch/phase.html