I only want one collision event

When detecting collisions in the usual manner:

  
local function collision( ball, event )   
 print("collision"); --this often gets printed twice or more  
 --award points  
 return true;  
end  
  
ball.collision = collision;  
ball:addEventListener( "collision", ball );  

I sometimes get 2 or more of these events. If I throw a ball at wall and it bounces off, I want to award points for the collision, but I end up awarding too many points because more than one collision gets detected. How do you prevent this? [import]uid: 52127 topic_id: 11907 reply_id: 311907[/import]

Have you tried only counting collisions happening in a certain phase. Such as:
[lua]local function collision( ball, event )
if event.phase == began then
– You could also use the “ended” phase
print(“collision”);
end
return true;
end

ball.collision = collision;
ball:addEventListener( “collision”, ball ); [/lua] [import]uid: 27965 topic_id: 11907 reply_id: 43456[/import]

that seems to work. thanks. [import]uid: 52127 topic_id: 11907 reply_id: 43474[/import]

You’re welcome! [import]uid: 27965 topic_id: 11907 reply_id: 43478[/import]