Add score when collision happens?

I’m setting up scoring for my app and was wondering if it’s possible to add to the score every time the main object in my app collides with something?  If so how do I go about that.

Here is what I have so far. 

local score = 0

local scoreText

scoreText = display.newText( “Score: 0”, 0, 0, native.systemFont, 18 )

scoreText:setReferencePoint(display.TopLeftReferenecePoint)

scoreText.x = display.screenOriginX + 40

scoreText.y = display.screenOriginY + 30

scoreText:setFillColor( 1, 0, 0)

local function addToScore(num)

score = score + num

scoreText.text = "Score: " … Score

scoreText:setReferencePoint(display.TopLeftReferenecePoint)

scoreText.x = screenLeft + 40

scoreText.y = screenLeft + 30

end

local function 

Can you post how you created the objects you want to collide?

–SonicX278

Also I’d recommend migrating to Graphics 2.0

Hi,

maybe something like this?

function addScoreOnCollision(event)
    if (event.phase == “began”) then
         if object1.myName == “mainObject” then
            addToScore()
         end
    end
end

and put event listener for collision.

Cheers,

SvenStp

Can you post how you created the objects you want to collide?

–SonicX278

Also I’d recommend migrating to Graphics 2.0

Hi,

maybe something like this?

function addScoreOnCollision(event)
    if (event.phase == “began”) then
         if object1.myName == “mainObject” then
            addToScore()
         end
    end
end

and put event listener for collision.

Cheers,

SvenStp