Scoring

Im pretty new to Corona and programming in general, but I am working on a game, and my scoring system isnt working…I want the score to change and increase on the screen but the only way i was able to do this was to have the score + 1 appearing on top of the score so there are about 500 numbers overlayed on top of each other in about a minute.

The way I got around this was to put a black box behind the number(shown in the code as rightScoreBack or ScoreBack) which make a new black box appear almost as much as the numbers so that when each number would appear, the black box would go on top of it so you could see the next number.

Here is my code:

score = 0

local rightScoreBack = display.newImage(“scoreback.png”, 0, 15)

rightScoreBack.xScale = 1.5

rightScoreBack.yScale = 1.5

local function updateScore()

score = score + 1

local scoreNumber = display.newText(score, 200, 0, nil, 50)

scoreNumber.xScale = 1.2

scoreNumber.yScale = 1.2

end

timer.performWithDelay(1, updateScore, -1)

local scoreText = display.newText(“score:”, 0, 0, nil, 50)

scoreText.xScale = 1.2

scoreText.yScale = 1.2

function updateScoreback(event)

local scoreBack = display.newImage(“scoreback.png”, 190, 15)

scoreBack.yScale = 1.5

end

timer.performWithDelay(1, updateScoreback, -1)

Any suggestions or better ways of doing this?

Thanks

Try this

I have created the text object outside of the updateScore function, and set the updateScore function to update only the text of the scoreNumber object. 

score = 0 local rightScoreBack = display.newImage("scoreback.png", 0, 15) rightScoreBack.xScale = 1.5 rightScoreBack.yScale = 1.5 local scoreNumber = display.newText(score, 200, 0, nil, 50) scoreNumber.xScale = 1.2 scoreNumber.yScale = 1.2 local function updateScore() score = score + 1 scoreNumber.text = score end timer.performWithDelay(1, updateScore, -1) local scoreText = display.newText("score:", 0, 0, nil, 50) scoreText.xScale = 1.2 scoreText.yScale = 1.2

Thanks. Works Great

Try this

I have created the text object outside of the updateScore function, and set the updateScore function to update only the text of the scoreNumber object. 

score = 0 local rightScoreBack = display.newImage("scoreback.png", 0, 15) rightScoreBack.xScale = 1.5 rightScoreBack.yScale = 1.5 local scoreNumber = display.newText(score, 200, 0, nil, 50) scoreNumber.xScale = 1.2 scoreNumber.yScale = 1.2 local function updateScore() score = score + 1 scoreNumber.text = score end timer.performWithDelay(1, updateScore, -1) local scoreText = display.newText("score:", 0, 0, nil, 50) scoreText.xScale = 1.2 scoreText.yScale = 1.2

Thanks. Works Great

how would I stop the score onCollision?

Why are you creating a new text object every time you update the score?    Just re-use the same one and you won’t have hundreds of objects getting hidden and overwritten (and taking up memory).   

scoreValue.text = tostring(newScoreValue)

can someone give me a whole scoring module with the highscore saving?

http://j-strahan.com/main/?p=79
will have some errors cause hasn’t been updated for gpx2.0

how would I stop the score onCollision?

Why are you creating a new text object every time you update the score?    Just re-use the same one and you won’t have hundreds of objects getting hidden and overwritten (and taking up memory).   

scoreValue.text = tostring(newScoreValue)

can someone give me a whole scoring module with the highscore saving?

http://j-strahan.com/main/?p=79
will have some errors cause hasn’t been updated for gpx2.0

jstrahan i can not find your main . i need it please 

my web host messed up my redirect and now you can’t get to the files from the web and I haven’t corrected it since there would be errors now with gpx2. I’m in the process of updating the files but haven’t gotten to high score yet. if you want give me your email and I can send the old version to you

I agree with you

jstrahan i can not find your main . i need it please 

my web host messed up my redirect and now you can’t get to the files from the web and I haven’t corrected it since there would be errors now with gpx2. I’m in the process of updating the files but haven’t gotten to high score yet. if you want give me your email and I can send the old version to you

I agree with you