Using the multi touch demo I’ve inserted a print statement to dump out the value of

-- Use this function to perform your initial setup
function setup()
    print("This example tracks multiple touches and colors them based on their ID")
    -- keep track of our touches in this table
    touches = {}

function touched(touch)
    if touch.state == ENDED then
        touches[] = nil
        touches[] = touch

-- This function gets called once every frame
function draw()
    background(0, 0, 0, 255)
    for k,touch in pairs(touches) do
        -- Use the touch id as the random seed
        -- This ensures the same fill color is used for the same id
        -- Draw ellipse at touch position
        ellipse(touch.x, touch.y, 100, 100)

Quite often the same value appears again after only 2 or 3 touches. Is there a way to prevent this?

I’m building up gestures based on successive touch events and am using the as the unique identifier for the gesture. If a gesture doesn’t exist with an id the same as any of the touches then create a new gesture. The problem is that if a is reused to quickly it tries to add it to the existing gesture rather than the new one.

From my experiments with, the id is valid only as long as the touch lasts. The can repeat itself over and over again with each touch and as far as I know there isn’t any way to stop it. Using as an identifier from one touch to another isn’t useful as you’re finding out.

Ok - cheers @dave1707. Moving on then, how is assigned? Will it ever be less than 5.000e8? By observation I’ve never seen it, but if anyone can shed more light that’d be appreciated (this would allow me to reassign the gesture id to an incremental count starting from 0 and not have to worry until the number of touches exceeded 5e8)

@West You might like to have a look at my touch library. I remember having a few issues with non-uniqueness of’s. What I ended up doing was distinguishing between active touches and non-active touches. So new touch data was only added to an old touch if the ids matched and the touch was active. If the old touch was non-active (ie had ended) then a new touch was created.

I see’s in the 4,199,000 to 5,220,000 range, but the majority are in the 216,000,000 to 255,000,000 range. Run this program and keep touching the screen with all your fingers. It will show you the low, high range and the count of the’s. There are 2 ranges that I’ve been seeing on my iPad1.


function setup()

function draw()
    background(40, 40, 50)
    str=string.format("%d -- %d     %d",l1,l2,lc)
    str=string.format("%d -- %d     %d",h1,h2,hc)

function touched(t)
    if > 100000000 then
        hc = hc + 1
        if > h2 then
            h2 =
        if < h1 then
            h1 =
    if < 100000000 then
        lc = lc + 1
        if > l2 then
            l2 =
        if < l1 then
            l1 =

There was some discussion long ago about these numbers. Unfortunately, I can’t find it now.

.@Andrew_Stacey That may have been something that I posted long ago, but I can’t find it either. The forum search function doesn’t work that well and only limits going back 2 pages of searches. So depending on the search, it only goes back a couple of months if that much. There are 54 pages of search information that’s being lost because of the limitation of the search function.

You can search using normal Google advanced search, limiting the search to the discussion URL, and it brings up a lot of stuff from the past.

Thanks for the info - @Andrew_Stacey - I’ve had a look at your touch library. I’ve also done a google search on the site and found some of the old discussions, but still don’t know how the value for touch/id is generated

@West According to the Codea-Runtime (file touch.h) the ID is an unsigned int which says that the maximum value is 4,294,967,295 (according to some bloke on the internet).

That’s(4,294,967,295) also the maximum money you can get in many games like temple run, subway surfers…
Using gamecih(on android). There must be a reason.

@Andrew_Stacey - thanks - wonder why it always seems to get assigned a high value in

@Saurabh (2^16)-1 is 4,294,967,295 - the maximum value which can be represented by a 16-bit number

@West Dunno. I’ve been trying to search the Apple docs since I believe that the id is assigned by iOS, not by Codea (supported by various references to touch->getID), but I can’t find any information on the actual touch data structure.