How to remove an object on collosion??

Here is some part of the code; I have two object below, canavar is the static object and kure is randomly produced with different images. I want to remove the kure object when it has collosion with canavar object. But I can not figure it how to do, I get error all the time. Any help will be highly appreciated

local canavar = display.newImage (“canavar.png”);
canavar.xScale = 0.5
canavar.yScale = 0.5
canavar.alpha = 0.8
canavar:setReferencePoint(display.CenterReferencePoint);
canavar.x = _GE * 0.5
canavar.y = _Y-60
canavar.myName = “canavar”
kareShape = { 50,-40, 50,-20, -50,-20, -50,-40 }
physics.addBody( canavar, “static”, { friction=0.5, bounce=0.3,shape=kareShape})
canavar:addEventListener( “touch”, dokun)

–obje
t = function()
local kure = {}
kure[1] = “kure1.png”
kure[2] = “kure2.png”
kure[3] = “kure3.png”
kure[4] = “kure4.png”
kure[5] = “kure5.png”
kure[6] = “kure6.png”
kure[7] = “kure7.png”
kure[8] = “kure8.png”
local sira = mran(1,#kure)
local yol = kure[sira]
local kure = display.newImage( yol )
kure:setReferencePoint(display.CenterReferencePoint);
kure.xScale = 0.5
kure.yScale = 0.5
kure.x = mran(50,_GE)
kure.y = 30
physics.addBody( kure, { friction=0.5, bounce=0.3,radius=30 } )
end

–Gruplar

–Zamanlay?c?lar
timer.performWithDelay( 1000, t, -1 )

–Olaylar
local function onLocalCollision( self, event )
if ( event.phase == “began” ) then
kure:removeSelf()
elseif ( event.phase == “ended” ) then

end
end

canavar.collision = onLocalCollision
canavar:addEventListener( “collision”, canavar )

kure.collision = onLocalCollision
kure:addEventListener( “collision”, kure ) [import]uid: 74718 topic_id: 12344 reply_id: 312344[/import]

hello, i dont know if it will do, but here is basic code for collision and removing
[lua]local physics = require(“physics”)
physics.start()
physics.setGravity(0,10)

local floor = display.newRect(0,0,400,10)
floor.x = display.contentWidth/2
floor.y = 320
floor.name = “floor”
physics.addBody(floor, “static”, {density=0, friction=0})

local cube = display.newRect(0,0, 50, 50)
cube.x = display.contentWidth/2
cube.y = 30
cube.name = “cube”
physics.addBody(cube, “dynamic”, {density=1,friction=1,bounce=0.3})

local function onCollision(event)
if event.phase == “ended” and event.other.name == “cube” then
cube:removeSelf()
end
end

floor:addEventListener(“collision”, onCollision)[/lua]

hope it’ll help [import]uid: 16142 topic_id: 12344 reply_id: 44997[/import]

Thank you but still nothing happens!! [import]uid: 74718 topic_id: 12344 reply_id: 45005[/import]

Here is the terminal output

Runtime error
…ler/Documents/Corona Calismalar/main.lua:104: attempt to index global ‘kure’ (a nil value)
stack traceback:
[C]: ?
…ler/Documents/Corona Calismalar/main.lua:104: in function <…ler calismalar calisma>
?: in function <?:214>
Runtime error
…ler/Documents/Corona Calismalar/main.lua:104: attempt to index global ‘kure’ (a nil value)
stack traceback:
[C]: ?
…ler/Documents/Corona Calismalar/main.lua:104: in function <…ler calismalar>
?: in function <?:214>
R [import]uid: 74718 topic_id: 12344 reply_id: 45006[/import] </…ler></…ler>

You should not modify collision objects during the actual collision event, as Box2D is still performing math on them. (I have found it seems ok to set isVisible = false immediately tho)

This is covered in the Collision Detection documentation: http://developer.anscamobile.com/content/game-edition-collision-detection#Important_Restriction:_Collision_handling

You need to wait until the collision event has finished resolving, so do something like this:

[lua]local function destroyKure()
display.remove( kure )
end

local function onLocalCollision( self, event )
if ( event.phase == “began” ) then
timer.performWithDelay( 1, destroyKure )
end
end

kure.collision = onLocalCollision
kure:addEventListener( “collision”, kure )[/lua] [import]uid: 70530 topic_id: 12344 reply_id: 45064[/import]