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.

if you want to remove anything on touch, then just do this:

1
2
3
if event.phase == "ended" then
display.remove(event.target)
event.target = nil

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
views:1343 update:2012/1/9 8:53:30
corona forums © 2003-2011