CODING PROBLEM PLEASE HELP!

[lua]module(…, package.seeall);
system.activate( “multitouch” )
function new()
local localGroup2 = display.newGroup();
local Planets = display.newGroup();
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, .5 )
--------------------Ship Picture--------------------

local function newShip()
local s = display.newGroup()
local ship = display.newImage(“ship.png”)
ship.x = 0; ship.y = 0;
local ship_body = {}
ship_body[“ship”] = {
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -23.9285714626312, 13.5 , -14.9285717010498, 3.78571510314941 , -8.71428489685059, 17.7142858505249 , -24.2857142686844, 26.2857143878937 }
} ,
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { 6.92856979370117, -21.6428565979004 , 12.3571434020996, -12.6428565979004 , 13.7857131958008, 4.21428489685059 , 7.28571319580078, 17.7142858505249 , -14.9285717010498, 3.78571510314941 , -10.2142858505249, -17.0714302062988 , -0.714284896850586, -28.5714302062988 }
} ,
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -14.9285717010498, 3.78571510314941 , 7.28571319580078, 17.7142858505249 , -8.71428489685059, 17.7142858505249 }
} ,
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { 7.28571319580078, 17.7142858505249 , 13.7857131958008, 4.21428489685059 , 21.7142868041992, 10.2857151031494 , 25.7857131958008, 18.2142858505249 , 24.8571434020996, 27.5714285969734 }
}
}

physics.addBody(s, “static”, unpack(ship_body[“ship”]))
s:insert(ship)
s:setReferencePoint(display.CenterReferencePoint)
return s
end

ship = newShip()
ship.x = _W/2; ship.y = _H/1.3
localGroup2:insert(ship);

-----------------------Cross hair right side--------------------------------
local crosshair = display.newImage(“crosshair.png”, {alpha = 0})
crosshair.x = _W/1.22; crosshair.y = _H/1.08;
crosshair.xScale = .5; crosshair.yScale = .5;
localGroup2:insert(crosshair);
function crosshair:touch(e)
if(e.phase == “began”) then
transright = transition.to( ship, { time= 500, x=(_W/1.18), y=(_H/1.3), transition = easing.linear} )
else
if(e.phase == “ended”) then
transition.cancel(transright)
end

end

end

------------------------------Cross hair right side ------------------------------
local crosshair2 = display.newImage(“crosshair.png”, {alpha = 0})
crosshair2.x = _W/5.22; crosshair2.y = _H/1.08;
crosshair2.xScale = .5; crosshair2.yScale = .5;
localGroup2:insert(crosshair2);
function crosshair2:touch(e)
if(e.phase == “began”) then
transleft = transition.to( ship, { time= 500, x=(_W/6.5), y=(_H/1.3), transition = easing.linear } )
else
if(e.phase == “ended”) then
transition.cancel(transleft)
end

end

end

-----Listeners-----------
crosshair:addEventListener(“touch”, crosshair);
crosshair2:addEventListener(“touch”, crosshair2);

------------------------Make The Asteroid Custom Physics Body----------------------------------------------

local function newAsteroid()
local g = display.newGroup()
local body = display.newImage(“asteroid2.png”)
body.x = 0; body.y = 0;
–body.xScale = .5; body.yScale = .5;
local physics_body = {}
physics_body[“asteroid2”] = {
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { 19.2166862487793, 12.2166848182678 , 8.43336868286133, 19.1083423495293 , -9.73293590545654, 19.9918744461611 , -15.8661971092224, 15.0162510871887 , -19.5666304826736, -11.8916568756104 , 1.7253532409668, -21.0417137145996 , 12.8586120605469, -16.2248115539551 , 21.9750823974609, -4.37486457824707 }
} ,
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -19.5666304826736, -11.8916568756104 , -15.8661971092224, 15.0162510871887 , -21.3499457985163, -6.98374938964844 }
}
}

physics.addBody(g, unpack(physics_body[“asteroid2”]))
g:insert(body)
g:setReferencePoint(display.CenterReferencePoint)

return g
end
----------------------------Spawn in the asteroids-------------------------------------------------------

local p = {};
local function spawnPlanets(number)

local function spawn(e)

local planet = p[e.count]
planet = newAsteroid()
planet.x = math.random((_W * .5)-100, (_W *.5)+100)
planet.y = -50
Planets:insert(planet)

if(e.count == number) then

timer.cancel(tmr)
tmr = nil
end

end

tmr = timer.performWithDelay(2000, spawn, number)

end

spawnPlanets(10)

------------------------------------------------COLISION DETECTOR----------------------------------------------
local function onLocalCollision( self, event )
if ( event.phase == “began” ) then
print “collision started”

elseif ( event.phase == “ended” ) then
----Stop all Listeners----
ship:removeEventListener( “collision”, ship )
crosshair:removeEventListener(“touch”, crosshair);
crosshair2:removeEventListener(“touch”, crosshair2);

Planets:removeSelf()

local overlay = display.newImage(“blackoverlay.png”, _W, _H, 132);
overlay:setReferencePoint(display.CenterReferencePoint);
overlay.x = _W/2; overlay.y = _H/2;
localGroup2:insert(overlay)

local lose = display.newImage(“lose.png”, _W, _H, 132);
lose:setReferencePoint(display.CenterReferencePoint);
lose.x = _W/2; lose.y = _H/4;
localGroup2:insert(lose)

----------------------------------------Menu Button PopUp--------------------

local menu = ui.newButton{
default = “menubutton.png”,
over = “menubuttonin.png”,
}
menu.x = _W/2.7; menu.y = _H/2;
menu.xScale = .7; menu.yScale = .7;
localGroup2:insert(menu)
menu.scene = “menu”

----------------------------------------------Retry Button PopUp-------------------

local retry = ui.newButton{
default = “retry.png”,
over = “retryin.png”,
}
retry.x = _W/1.6; retry.y = _H/2;
retry.xScale = .7; retry.yScale = .7;
localGroup2:insert(retry)
retry.scene = “level1”

menu:addEventListener(“touch”, changeScene)
retry:addEventListener(“touch”, changeScene)

end
end

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

------------------------------------Test Code-----------------------------------------------
–local function win()
–local win = display.newImage(“win.png”)
–win.x = _W/2; win.y = _H/4;

–localGroup2:insert(win);
–end


----------------Change Scene Director Class Code-----------------------------------
function changeScene(e)
if(e.phase == “ended”) then
if(e.target.scene) then
director:changeScene(e.target.scene);
end
end
end

---------------Test Code-----------------------------
–timer.performWithDelay(28000, win )

----Director Class—

return localGroup2;
end[/lua]

This is my code for a game that I’m making. I need help! I’m using the director class. I want to make it so the asteroids disappear from the screen once the collision happens. If anyone can help me with this problem they will be my best friend forever.

Please help :slight_smile: [import]uid: 29181 topic_id: 9388 reply_id: 309388[/import]

what’s your error? Or you need help setting up the collision? [import]uid: 12455 topic_id: 9388 reply_id: 34347[/import]

for collsion, this is what I normally do

this is not tested, but it should give you an idea.
[lua]-- make your ship local
local ship

– setup the collision function first
local onCollision = function (self, event)
if event.phase == “began” then
– do something

elseif event.phase == “ended” then
– do something else

– you don’t have to remove the collision listener

self:removeSelf()
self = nil
event.other:removeSelf()
event.other = nil
end
end
ship = display.newImageRect(“watever.png”, 50,50)
ship.x = 240
ship.y = 160
ship.name = “ship”
physics.addBody(ship, “kinematic”, {density = 1, friction = 05})
ship.collision = onCollision
ship:addEventListener(“collision”, onCollision)
[import]uid: 12455 topic_id: 9388 reply_id: 34349[/import]

self = nil is useless.

“self” is just a local variable in Lua, so its scope is limited to the function anyway. What you want to do is nil “ship”. [import]uid: 51516 topic_id: 9388 reply_id: 34352[/import]

I think you guys are misunderstanding my question. I’m trying to remove all of the asteroids from the screen when the collision happens. I can’t get it to work. The function newAsteroid makes the asteroid custom physics body and the function spawnPlanets spawns the asteroids at the top of the screen. The asteroids then fall down and if they hit the ship, the a menu screen popup appears. I want at that time for all of the asteroids to disappear and for the retry but to reload the scene, but I can’t get it to work. Help please. [import]uid: 29181 topic_id: 9388 reply_id: 34381[/import]

I might try something tomorrow but I’m gonna give you an advice in the meantime:
DON’T SHOUT

You just sound rude. And saying you’ve got a coding problem in your post title is useless as everybody posting here got a problem. You should change your title to something more accurate. [import]uid: 51516 topic_id: 9388 reply_id: 34382[/import]

I was posting to see if anyone was kind enough to help me debug my program. I guess since “everyone has a coding problem” your not willing to help. I’m 16 years old and I’m new to Lua. I was just asking if someone could help and fortunatly one person was kind enough to help. Thanks teex! If you know how to fix this I would appreciate your feedback, but don’t expect other people to help you with your coding problems when you don’t contribute back to the community. Ever since I’ve started programing on Corona, I’ve been an active member on the forums and others appricate it, so if your mad that I’m asking a question that people can choose not to answer SCREW YOU! [import]uid: 29181 topic_id: 9388 reply_id: 34383[/import]

Real mature. 16 years old sounds about right. [import]uid: 51516 topic_id: 9388 reply_id: 34384[/import]

UMAD BRO? [import]uid: 29181 topic_id: 9388 reply_id: 34389[/import]