Boucing ball and collision detection

I got it working  . All I have to do is add scoring and and a game over /restart section to my game.

I also have to improve the ball and paddle movement. but at least I am almost there.

I have spent a month this cause I only get to spend 1 to 2 hrs a week on this and I am brand new to programming

It seems as if name.collision can’t  be name.collision2

see my code below

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- ----pong game ----- -- Your code here local physics = require("physics") physics.start() ----- ----left side of room local myleft = display.newLine( 10, -50, 10, 1000 ) physics.addBody( myleft, "static" ,{density = 0, friction = 0}) ----rightside of room local myright = display.newLine( 310, 900, 310, -50 ) physics.addBody( myright, "static" ,{density = 0, friction = 0}) --center of room local mycenter = display.newLine( 160, 550, 170, -50 ) ---------------------------------------------------------------------- local creategamescreen local startgame local moveball local ballcollison ------creates first screen a player sees function creategamescreen() startgametext = display.newText( "Tap here to start the game!", 150, 250, "Helvetica", 24 ) startgametext:setFillColor( 1, 0, 0 ) local function removetxt() display.remove(startgametext) startgame() end startgametext:addEventListener ( "tap", removetxt ) end creategamescreen() ----this starts the game function startgame(event) timer.performWithDelay ( 3000, moveball ) ------------------------------------------------------------------- end -- Create a rectangle player one myRect = display.newRect( 0, 0, 30, 100 ) myRect.x =40 myRect.y =125 --- paddle for computer player cpupaddle=display.newImage ("paddle1.png") cpupaddle.x =270 cpupaddle.y =325 physics.addBody( cpupaddle, "static" ,{density = 1.0, friction = .3, bounce = 0}) physics.addBody( myRect, "static" ,{density = 1.0, friction = .3, bounce = 0}) ---------------move paddle player#1 local function ontouch (event) if event.phase == "ended" then ----moves it any where i click-- --- transition.to (myRect,{x=event.x, y=event.y}) ---just moves it up and down transition.to (myRect,{y=event.y}) end end Runtime:addEventListener("touch", ontouch) ----draw ball function moveball () ---local myCircle = display.newCircle( 200, 200, 30 ) myCircle = display.newCircle( 200, 200, 30 ) myCircle:setFillColor( 0.5 ) physics.addBody(myCircle,"dynamic",{density=0.1,bounce = .8, friction = 0}) --myCircle.x =330 myCircle.x =300 myCircle.y =125 ----this works to make the ball bounce off the paddle but ball moves at random for x & y myCircle:setLinearVelocity(math.random(-600,-300),math.random(-100,500)) ---this moves cpupaddle transition.to (cpupaddle,{x=cpupaddle.x, y=cpupaddle.y + math.random(-250,200)}) end ---collsion notificatons when ball hits paddle and move paddle 2 function ballcollison( self, event) --added if ( event.phase == "began" ) then print ("event began") elseif ( event.phase == "ended" ) then print ("ball hit paddle") timer.performWithDelay ( 4000, moveball ) end end local myCircle = display.newCircle( 200, 200, 30 ) myCircle:setFillColor( 0.5 ) myCircle.alpha =0 myRect.collision = ballcollison myRect:addEventListener("collision") myCircle.collision = ballcollison myCircle:addEventListener( "collision" ) ---leftwall collision ---collsion notificatons when ball hits left wall function leftwallcollison( self, event) ----added if ( event.phase == "began" ) then print ("event left wall began") elseif ( event.phase == "ended" ) then print ("ball hit left wall") end end myleft.collision = leftwallcollison myleft:addEventListener( "collision" ) ---right collision ---collsion notificatons when ball hits right wall function rightwallcollison( self, event) ----added if ( event.phase == "began" ) then print ("event right wall began") elseif ( event.phase == "ended" ) then print ("ball hit right wall") end end myright.collision = rightwallcollison myright:addEventListener( "collision" )