Need Help With Score Keeping

My game's score is actually money (i.e. $1.42) and I'm having trouble getting it to work the way I want it. I tried having dollars and cents variables, but the cents would only display one digit until it was 10 or more.

Can you guys think of a better way to do this?

P.S. I tried using three variables (one for each place value), but it was a little slow when updating because it had to check if each place value was 10 or more.

http://lua-users.org/wiki/FormattingNumbers
look at this, maybe it will help you

It says that this

1
2
amount = 22333444.5634
print(format_num(amount,2,"$"))

I would simply do:

1
   text = string.format("$%.02f", score)

So then how would I add a score value to it? Could you write a quick example, please?

Well lets assume you have a display text object for your score:

1
2
3
4
5
6
7
8
9
10
11
12
local score = 0
local scoreText = display.newText(string.format("$.02f", score), 0, 0, "Helvetica", 20)
scoreText.x = display.contentWidth / 2 -- centering, place it where you want it....
scoreText.y = 15
scoreText:setTextColor(255,255,255)
 
....
-- later on.....
....
 
score = score + amountEarned  -- amountEarned is how much you want to add to the score.
scoreText.text = string.format("$.02f", score)

It doesn't seem to be working. :/

It just constantly displays "$0.02f".

textMoney = display.newText(string.format("$0.02f", money), 0, 20, native.systemFont, 75)

oops typeo;

$%.02f

need that percent sign.

Thanks!

views:1554 update:2011/12/28 9:26:54
corona forums © 2003-2011