Check for collision outside of function?

Hey,

I have this function to randomly drop Gems in to the game (modified from the ManyCrates example):

[lua]function newGem()
rand = math.random( 100 )

if (rand < 60) then
gem1 = display.newImage(“Gem1.png”);
gem1.x = 60 + math.random( 160 )
gem1.y = -100
physics.addBody( gem1, { density=0.9, friction=0.3, bounce=0.3} )

elseif (rand < 80) then
gem2 = display.newImage(“Gem2.png”);
gem2.x = 60 + math.random( 160 )
gem2.y = -100
physics.addBody( gem2, { density=1.4, friction=0.3, bounce=0.2} )

else
gem3 = display.newImage(“Gem3.png”);
gem3.x = 60 + math.random( 160 )
gem3.y = -100
physics.addBody( gem3, { density=0.3, friction=0.2, bounce=0.5} )

end
end[/lua]

at the bottom of the screen I have a Boy that has to catch the gems. How do I check for collision betwen these objects? [import]uid: 12521 topic_id: 4586 reply_id: 304586[/import]

If i do it this way:

[lua] local function onGemCollision( self, event )
if ( event.phase == “ended” ) then
score = score + 150
scoreDisplay:setText( score )

end
end

gem1.collision = onGemCollision
gem1:addEventListener( “collision”, gem1 )[/lua]

the terminal says that gem1 has a nil value. Why? [import]uid: 12521 topic_id: 4586 reply_id: 14497[/import]