Removing Objects in a table

In my game, enemies are constantly spawning at a rate of 1 per 2 seconds, and all going into a table. When one is tapped, I want only this one to go away.

I tried

function destroy(obj)
obj:removeSelf()
end

function ship:hit(e)
f = “200”
if f < freq1 + 20 and f > freq1 - 20 or f < top1 + 20 and f > top1 - 20 then
destroy(self)
print(“hit”)
return true;
end
end
Runtime:addEventListener(“enterFrame”, hit)

I get assertion failed errors. [import]uid: 59735 topic_id: 20113 reply_id: 320113[/import]

if you want to remove anything on touch, then just do this:
[lua]if event.phase == “ended” then
display.remove(event.target)
event.target = nil[/lua] [import]uid: 16142 topic_id: 20113 reply_id: 78575[/import]

not working… [import]uid: 59735 topic_id: 20113 reply_id: 78583[/import]

[lua]local function ship(index)

local ship = display.newImage(“quarter.png”)
ship:scale(".5",".5")
if ships[index].rot == true then
ship:rotate(“180”)
end
ship.x=“750”
ship.y= ships[index].posy
freq1 = ships[index].top
top1 = ships{index].top
function check(event)
f = 500
txt.text = f
if f < freq1 + 20 and f > freq1 - 20 or f < top1 + 20 and f > top1 - 20 then
print(“hit”)
remove(self)
end
return true
end

Runtime:addEventListener(“enterFrame”, check)

local function move()
ship.x = ship.x - 3
end
timer.performWithDelay(20, move, -1)

return ship
end [import]uid: 59735 topic_id: 20113 reply_id: 78610[/import]

Look at line 17. That isn’t going to work. Your not passing self so how can you remove it ?

[import]uid: 84637 topic_id: 20113 reply_id: 80714[/import]