Hi, ok so basically my problem is trying to remove an objecct attach to an object. Ok so basically I have plane spawning every 1 second and is flying across the screen. As the plane is flying across the scene is it has the little circles on attach to the plane. So when the plane is removed I get an error saying this
Runtime error
/Users/sebitttas/Desktop/Helicopter pixel/menu.lua:55: attempt to index upvalue ‘enem4’ (a nil value)
stack traceback:
[C]: ?
/Users/sebitttas/Desktop/Helicopter pixel/menu.lua:55: in function ‘_listener’
The error goes to this code
[code]
local wall = display.newRect(-10, 0, 10, 320)
wall.hit = “wall”
localGroup:insert(wall)
physics.addBody(wall ,“static”)
local function enemies4 ()
particle = false
local enem4 = display.newRect(0,0,100, 100)
enem4.y = math.random(30, 290)
enem4.x = 600
enem4.isFixedRotation = true
physics.addBody (enem4, {bounce=0.6, isSensor = true})
transition.to (enem4, {time = 5000, x=-50})
enem4.hit = “enem4”
enem4.hits = 0
localGroup:insert(enem4)
enem4:addEventListener(“collision”, enem4)
function enem4:collision (event)
if event.other.hit == “wall” then
enem4:removeSelf()
enem4 = nil
particle = true
end
if event.other.hit == “heli” then
display.remove(enem4)
Life = Life - 1
health.text = “Health:”… Life
enem4 = nil
end
end
local badtwin = display.newRect(0,0 , 10, 10)
badtwin.x = enem4.x - 30
badtwin.y = enem4.y
badtwin.hit = “badtwin”
physics.addBody (badtwin, {bounce=0.6})
localGroup:insert(badtwin)
transition.to (badtwin, {time = 3000, x= - 200})
badtwin:addEventListener(“collision”, badtwin)
function badtwin:collision (event)
if event.other.hit == “wall” then
badtwin:removeSelf()
badtwin = nil
end
if event.other.hit == “heli” then
badtwin:removeSelf()
Life = Life - 1
health.text = “Health:”… Life
badtwin = nil
end
end
local function good()
if particle == false then
local circle = display.newCircle(0,0,3)
circle:setFillColor(math.random(103),math.random(73),math.random(136))
circle.x = enem4.x + 5
circle.y = enem4.y
physics.addBody (circle, {bounce=0.6, isSensor = true})
circle:addEventListener(“collision”, circle)
function circle:collision (event)
if event.other.hit == “wall” then
circle:removeSelf()
circle = nil
end
end
local x1 = enem4.x + math.cos(math.random(360)) * math.random(5)
local y1 = enem4.y + math.cos(math.random(360)) * math.random(20,30)
transition.to(circle,{x = x1,y = y1,alpha = 0,time = 500,
onComplete = function() circle:removeSelf() circle = nil end })
enem4:toFront()
end
end
particles = timer.performWithDelay(1, good, -1)
end
bad4 = timer.performWithDelay(2000, enemies4, -1)[/code]
By the way the code is a plug. So what I’m trying to remove is spawn two objects at the same time spawning the circle and the plane which is the square, and removing them at the same time since the circle is at the same coordinate as the plane
[import]uid: 17058 topic_id: 22771 reply_id: 322771[/import]