Removing Objects after collision

Thanks so much for the help so far. I am creating a word game. I break up the letters into individual sprites and the accompanying physics object. I then drag them around to “slots”. Once they hit their slot, I would like to remove them. I am using collision detection to get this done. THe problem I have is that when I have a word with the same letters like gOOse, it removes both sprites when I collide with one of the letters “letter[e] = nil” removes both Os in one go.


for z=1,#new_word do    -- create 5 objects
        letter[z] =readImage("Dropbox:"..characters[z])
        letter_diam=(letter[z].width+letter[z].height)/2
        rande_x = math.random(200,514)
        rande_y = math.random(150,268)
        rando_x = math.random(514,824)
        rando_y = math.random(500,618)
        if (z % 2 ~= 0) then
            table.insert(tab,vec2(rande_x,rande_y))
            -- Create the physics objects --
            p_letter[z] = physics.body(CIRCLE,letter_diam/2)
            p_letter[z].x = rande_x
            p_letter[z].y = rande_y
            p_letter[z].info=characters[z]
        else
            table.insert(tab,vec2(rando_x,rando_y))
            -- Create the physics objects --
            p_letter[z] = physics.body(CIRCLE,letter_diam/2)
            p_letter[z].x = rando_x
            p_letter[z].y = rando_y
            p_letter[z].info=characters[z]
        end
    end
    for z1=1,#new_word do    -- create 5 objects
        target[z1] =readImage("Dropbox:"..characters[z1])
        table.insert(tab1,vec2(x_loc,rh/2))
        table.insert(tab_orig,vec2(x_loc,rh/2))
        -- Create the physics objects --
        p_target[z1] = physics.body(CIRCLE,letter_diam/2)
        p_target[z1].x = x_loc
        p_target[z1].y = rh/2
        p_target[z1].info="t"..characters[z1]
        x_loc=x_loc+100
    end

function collide(contact)
    if contact.state == BEGAN then 
        if "t"..contact.bodyA.info==contact.bodyB.info then
            print(contact.bodyA.info)
            print("hit")
            for e,f in pairs(tab_orig) do
            done=0
                if contact.bodyA.info == characters[e] and done ==0 then
                    letter[e] = nil
                    print("done")
                    done=1
                    break
                end
            end
        end
    end
end

Also is there a way to export for Iphone? I would like these all to be universal apps

please put this ~~~
before and after your code

@swiftjuan I added the 3 ~ to your code so it formats correctly. If you want to see how to do it in the future, press ‘Edit’ above your code to see the 3 ~ before and after the code.

Thanks I will do that from now on.

@swiftjuan Ignore my last suggestion. I didn’t see the break command that you have.

@swiftjuan In your contact function, once you hit a match and do what you need to do, you should then exit the function so you don’t check anymore letters.

@swiftjuan - it may be that the contact is “starting” more than once, and so your deletion is repeating itself. Your variable “done” may look as though it prevents this, but it actually does nothing.

I note you are deleting from the letters table but not the other tables you have set up, eg for physics objects. Don’t forget to delete physics objects before setting them to nil (see built in reference).