How to detect and track Touches?

I am new to codea and am having trouble finding a way to track touches.

What i want to happen is:
when touched, do etc. (then this branches)
If another touch happens, If touch is removed then undo said thing from above.
do this

Details: So what im doing is if i touch the screen i will get the cords of my touch and ID on the screen(not in output). Then if i were to touch the screen with a second finger, i would get the cords and ID of that touch also. What im having trouble with is finding a way to distinguish between 1 finger on the screen or 2+.

I haven’t yet fully grasped how the variables work in this language yet either.

You might want to look at the included Multi-Touch example project. This assigns each touch a random colour, and keeps them organised by their ID.

I had about the same problem to set some camera control. Here is how i solved it

CameraControl = class()

function CameraControl:init()
    -- this is for touch control
    self.touches = {}
    self.x0 = 0
    self.y0 = 0
    self.d0 = 100

function CameraControl:touched(touch)
    if touch.state == ENDED then
        self.touches[] = nil
        self.touches[] = touch
    local n = 0
    for i,v in pairs(self.touches) do n = n + 1 end
    -- if exactly one touch then move
    if n==1 then self:move(touch) end
    -- if exactly 2 touches then zoom
    if n==2 then self:zoom() end

You have in your main setup to define a CameraControl() object,

function setup()
     camControl = CameraControl()

and to call it in the touch function

function touched(touch)

If there is just one touch I proceed normally by passing the touch variable to my move function. If there are 2 touches exactly, then i let the zoom function analyse the self.touches array. Since the touch id is not an easy nuber to manage, i first transfer everything to a table t indexed by 1 and 2. This is very un-elegant, but it works. Probably someone will post something better later.

function CameraControl:zoom()
    local t = {}
    local n = 1
    for i,touch in pairs(self.touches) do
        t[n] = touch
        n = n + 1
   -- rest of you code :

This is why I wrote my touch controller/handler. You can read a bit about it at

Is there indepth tutorials of touch mechanics? because i want to make a control pad for movement on a side scroller game im currently making, but the touch function doesnt get called if the touch is not moving.

for example if i were to put my finger on the left arrow and try not to move it the character would only move only because my finger is moving a little. I want it so that if my finger is on it, i dont want to have to move my finger for it to move my character

Okay, so i did not know currentTouch existed. I made it so that i force call Touched(touch), but now if i end my touch while on the key to move then it continues to move that way, never stopping till i press another place on the screen.