Game Score

Hi all i managed to display score on my game but every time i break a item my score doesn’t go up what function or listener to i need to invoke to track the score of the player ??? Total newbie here Thanks [import]uid: 90369 topic_id: 24448 reply_id: 324448[/import]

Hey miguel, you are incrementing the score, but you are not updating the showScore object, which actually has the text. Try adding something like
[lua]showScore.text = "Score: " … score;[/lua]
after line 10

[import]uid: 135765 topic_id: 24448 reply_id: 98912[/import]

This is basically what I have in the game I’m working on.

[lua]local score = 0;

local showScore = display.newText ("Score: "…score, 18, 15, “BradyBunch”,30)
showScore:setTextColor(250,250,0);
showScore:setReferencePoint(display.CenterLeftReferencePoint);

–Increase the score every time something happens

local function ObjBreaking()
score = score + 1;
showScore.text = "Score: " … score;
end[/lua]

I hope that makes sense and is helpful to you. So basically you want to increase your score every time the braking happens.

EDIT: Whoops, r.delia you’re right. I did have that line in my code but forgot to add it in. I’ll edit my post. [import]uid: 123298 topic_id: 24448 reply_id: 98897[/import]

Hey Dude the score code works fine in displaying the score… But it doesn’t track the score the sample code im using is ansca-Samurai-Fruit… i think its some touch handler i got to change thanks for your help… [import]uid: 90369 topic_id: 24448 reply_id: 99018[/import]

I’m sorry to butt in like this but I got my scoring to work but when the score updates it just updates on top of each other. how could i make it so that it replaces the old score
[lua]local function blueDotFunction ()
–Create white circle and place at top of screen
local bluePdot = display.newCircle( 0,0,20,20)
bluePdot:setFillColor(0,0,255)
bluePdot:setReferencePoint(display.centerReferencePoint)
bluePdot.x = rand(60, _W - 50); bluePdot.y = rand(70, _H - 50)
physics.addBody( bluePdot,“dynamic”, { density = -0.8, friction = 0.3, bounce = .7, radius = 20 } )
number = table.maxn(blueDots) – We get the max number in the table and assign ‘number’ that value
table.insert(blueDots, number+1, bluePdot) – Insert each blue object into a table so we can handle each one individually later

function bluePdot:touch(event)
if (event.phase == “ended”) then
audio.play(pop);
removeDot(self)
print(“pop”)

score = score + 10
local scoreText = display.newText("score: " … score, 0, 0, “native.systemFont”, 30)
scoreText:setReferencePoint(display.CenterLeftReferencePoint)
scoreText.x = 35
scoreText.y = 10
return true

end
end

bluePdot:addEventListener(“touch”, bluePdot)
bluePdot:addEventListener(“touch”, hitDots)

end

timer.performWithDelay(100, blueDotFunction, numberOfBule)
[import]uid: 121743 topic_id: 24448 reply_id: 102936[/import]

Score systems in Corona have 4 parts to display the score:

  1. A value to hold the score
  2. A way to change the score value
  3. A way to display the score.
  4. A way to update the display with a new score.
    It sounds like you have accomplished 1-3.

The #3 part you probably created a display object using the API call: display.newText().

Let’s say you called it:

scoreDisplay = display.newText(score, 0, 0, system.nativeFont, 24)
To change the information that is shown you simply do:

scoreDisplay.text = score

where ever you change your score. [import]uid: 19626 topic_id: 24448 reply_id: 102948[/import]

Hi i been trying for a whole week now to get my score to work when the fruit is sliced… its driving me mad could i do this when fruit is chopped track that so it scores up ??? here is some code… How would i track the chop in the score code ??? sorry total newibe here also can someone tell me if my theory is right ??? Thanks
– Return a random value between ‘min’ and ‘max’
function getRandomValue(min, max)
return min + math.abs(((max - min) * math.random()))
end

function playRandomSlashSound()

audio.play(slashSounds[“slash” … math.random(1, 3)])
end

function playRandomChoppedSound()

audio.play(choppedSound[“chopped” … math.random(1, 2)])
end

function getRandomSplash()

return display.newImage(splashImgs[math.random(1, #splashImgs)])
end

function chopFruit(fruit)

playRandomChoppedSound()

createFruitPiece(fruit, “top”)
createFruitPiece(fruit, “bottom”)

createSplash(fruit)
createGush(fruit)

fruit:removeSelf()
end
local score = 0;

local showScore = display.newText ("Score: "…score, 18, 15, “BradyBunch”,30)
showScore:setTextColor(250,250,0);
showScore:setReferencePoint(display.CenterLeftReferencePoint);

–Increase the score every time something happens

local function ObjBreaking()
score = score + 1;
showScore.text = "Score: " … score;
end [import]uid: 90369 topic_id: 24448 reply_id: 102968[/import]

Where are you calling ObjBreaking()?
[import]uid: 19626 topic_id: 24448 reply_id: 102991[/import]

@robmiracle Dude im not calling ObjBreaking()? function anywhere… if i understand you right im suppose to call it when the fruit is being sliced for the score to update ??? Thanks [import]uid: 90369 topic_id: 24448 reply_id: 103071[/import]

That’s exactly right. You have all the right code to update your score in that function, but if you never call it, the score will never update. [import]uid: 19626 topic_id: 24448 reply_id: 103087[/import]

im sick of this i have replaced objbreak() with every function available in the samurai fruit code… The score will still not work and i even been reading up on lua functions on the net… No luck im giving up on this sample code :frowning: [import]uid: 90369 topic_id: 24448 reply_id: 103629[/import]

Try this:

function chopFruit(fruit)  
  
 playRandomChoppedSound()  
  
 createFruitPiece(fruit, "top")   
 createFruitPiece(fruit, "bottom")  
  
 createSplash(fruit)  
 createGush(fruit)  
  
 fruit:removeSelf()  
  
 ObjBreaking()  
end  

But you will have to move the local function ObjectBreaking() code before the function chopFruit()
[import]uid: 19626 topic_id: 24448 reply_id: 103705[/import]

@robmiracle Thanks dude ill try that tonight ill let you know… Thanks [import]uid: 90369 topic_id: 24448 reply_id: 104414[/import]

Thanks i tried the code before and after then top and bottom… it still doesn’t work :frowning: right it seems like im going to have to pay some one to do it for me because its been well over a few weeks and im sick of it… What would some one charge to get the score working with a couple of score features??? Thanks [import]uid: 90369 topic_id: 24448 reply_id: 104772[/import]

@robmiracle You rock i got the score working dude :slight_smile: for some reason it works outside the main function it wouldn’t work before the chop fruit ?? Thanks [import]uid: 90369 topic_id: 24448 reply_id: 108882[/import]