collision with more than 2 couple of objects

Hi, I did a collision between 2 couple of objects (lines-player & token-player) using the following code:

function onCollision( event )  
 if ( event.phase == "began" ) then  
 if event.object1.myName == "lines" and event.object2.myName == "player" then  
   
 my code here...  
  
 end  
  
 elseif ( event.phase == "ended" ) then  
 if event.object1.myName == "token" and event.object2.myName == "player" then  
  
  
  
 end  
 end  
  
 end   
  
  
 Runtime:addEventListener( "collision", onCollision )  

Well, now I would like to add another collision with another couple of objects (boost-player), but I don’t know how to do that and I’m looking for a way to solve this little problem, any suggestion?

Thanks! :slight_smile: [import]uid: 122056 topic_id: 35311 reply_id: 335311[/import]

What exactly are you trying to do? If you are just trying to detect which types of objects are colliding, then why not name them uniquely and test for each type? I see you’re pretty much doing that already with the .name property, but what else do you want?

Something like this?

[lua]function onCollision( event )
if ( event.phase == “began” ) then
if event.object1.myName == “lines” and event.object2.myName == “player” then
– my code here…
elseif event.object1.myName == “lines2” and event.object2.myName == “player” then
– my code here…
elseif event.object1.myName == “lines3” and event.object2.myName == “player” then
– my code here…
end
elseif ( event.phase == “ended” ) then
if event.object1.myName == “token” and event.object2.myName == “player” then
end
end
end

Runtime:addEventListener( “collision”, onCollision )[/lua] [import]uid: 8271 topic_id: 35311 reply_id: 140343[/import]

Exactly! Something like that!

Thanks you have been very useful
[import]uid: 122056 topic_id: 35311 reply_id: 140360[/import]

What exactly are you trying to do? If you are just trying to detect which types of objects are colliding, then why not name them uniquely and test for each type? I see you’re pretty much doing that already with the .name property, but what else do you want?

Something like this?

[lua]function onCollision( event )
if ( event.phase == “began” ) then
if event.object1.myName == “lines” and event.object2.myName == “player” then
– my code here…
elseif event.object1.myName == “lines2” and event.object2.myName == “player” then
– my code here…
elseif event.object1.myName == “lines3” and event.object2.myName == “player” then
– my code here…
end
elseif ( event.phase == “ended” ) then
if event.object1.myName == “token” and event.object2.myName == “player” then
end
end
end

Runtime:addEventListener( “collision”, onCollision )[/lua] [import]uid: 8271 topic_id: 35311 reply_id: 140343[/import]

Exactly! Something like that!

Thanks you have been very useful
[import]uid: 122056 topic_id: 35311 reply_id: 140360[/import]