Combo score

Hi everyone.

I’v been making my first game for a few months now and
i am very pleased with the progress i am making, considering im
total amateur with mimimum time invested in actual learning to code.

I want to improve my game with a combo bonus score but i just
can’t find a solution to the problem.

Hopefully someone knows how to deal with this:

Scoring is based on function detecting collision.

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

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

and so on…

Now, the question is, how to get bonus score if player hits
blue-red-blue-red in a row for example?

Cheers, SvenStp.

I would create
A table that keeps track of that like

local history ={}

history[#history+1] = color

I think a table is a bit over the top for this simple combo function (as you only need to know if the last and the current colors differ).

I would try something like this:

local currentCombo = 0 local lastColor function addScoreOnCollision1(event) if (event.phase == "began") then if object1.myName == "blue" then if lastColor == object1.myName then currentCombo = 0 end currentCombo = currentCombo + 1 lastColor = object1.myName addToScore(currentCombo) end end end 

So you’ve got to variables, one keeps track of the last color and the other of the current Combo. If the last and the current color match the combo is reset.

Now you just need to integrate the combo value into your addToScore function.

Greetings

Torben

Thank you both scottrules44 and torbenratzlaff for your answers!  I tried few table combinations, but they just dont work for me, probably becose i still dont understand tables good enough.

On the other hand, torben, your answer is more clear to me, but as i understand you wrote combo score=0 until colour change.

Random color changing collisions is one point each, its challenging but normal gameplay.

To make it more interesting i want to give the player “assignment” for bonus points.

He must “chase” for example 3 blue collisions plus 3 yellow for 10 bonus points, or all six colours one by one for 20 bonus points and so on…

I hope i made it more clear this time…

Cheers

SvenStp

I would create
A table that keeps track of that like

local history ={}

history[#history+1] = color

I think a table is a bit over the top for this simple combo function (as you only need to know if the last and the current colors differ).

I would try something like this:

local currentCombo = 0 local lastColor function addScoreOnCollision1(event) if (event.phase == "began") then if object1.myName == "blue" then if lastColor == object1.myName then currentCombo = 0 end currentCombo = currentCombo + 1 lastColor = object1.myName addToScore(currentCombo) end end end 

So you’ve got to variables, one keeps track of the last color and the other of the current Combo. If the last and the current color match the combo is reset.

Now you just need to integrate the combo value into your addToScore function.

Greetings

Torben

Thank you both scottrules44 and torbenratzlaff for your answers!  I tried few table combinations, but they just dont work for me, probably becose i still dont understand tables good enough.

On the other hand, torben, your answer is more clear to me, but as i understand you wrote combo score=0 until colour change.

Random color changing collisions is one point each, its challenging but normal gameplay.

To make it more interesting i want to give the player “assignment” for bonus points.

He must “chase” for example 3 blue collisions plus 3 yellow for 10 bonus points, or all six colours one by one for 20 bonus points and so on…

I hope i made it more clear this time…

Cheers

SvenStp