Can't get numbers to right justify

Hi,

I’m doing something that I thought would be easy and I just can’t get it to work.

I have 3 score numbers that I want all lined up with right justification so they would look something like this:

      90

    990

99999

Here is my code:

local round_ending_scoreOptions =
{
  text=string.format("%-15u", 0),
  font = gameSettings.titleFont,
  fontSize = 20,
 width=200,
  align = “right”  --new alignment parameter
}

round_ending_score = display.newText( round_ending_scoreOptions )
round_ending_score:setFillColor(0, 0, 0)
round_ending_score.anchorX = 1
round_ending_score.x = stoneBench.x  + stoneBench.width/2 -150
round_ending_score.y = scoreTextLine2.y
round_ending_score:toFront()
round_ending_score.alpha = 0
WTgroup:insert( round_ending_score )

local round_ending_lifetime_scoreOptions =
{
  text=string.format("%-15u", 0),
  font = gameSettings.titleFont,
  fontSize = 20,
width=200,
   align = “right”  --new alignment parameter
}

round_ending_lifetime_score = display.newText( round_ending_lifetime_scoreOptions )
round_ending_lifetime_score:setFillColor(0, 0, 0)
round_ending_lifetime_score.anchorX = 1
round_ending_lifetime_score.x = stoneBench.x  + stoneBench.width/2 -150
round_ending_lifetime_score.y = scoreTextLine3.y
round_ending_lifetime_score:toFront()
round_ending_lifetime_score.alpha = 0
WTgroup:insert( round_ending_lifetime_score )

local round_ending_scoreToNextPlaneOptions =
{
  text=string.format("%-15u", 0),
  font = gameSettings.titleFont,
  fontSize = 20,
 width=200,
  align = “right” 
}

round_ending_scoreToNextPlane = display.newText( round_ending_scoreToNextPlaneOptions )
round_ending_scoreToNextPlane:setFillColor(0, 0, 0)
round_ending_scoreToNextPlane.anchorX = 1
round_ending_scoreToNextPlane.x = stoneBench.x  + stoneBench.width/2 -150
round_ending_scoreToNextPlane.y = scoreTextLine4.y
round_ending_scoreToNextPlane:toFront()
round_ending_scoreToNextPlane.alpha = 0
WTgroup:insert( round_ending_scoreToNextPlane )

Anyone see what I am doing wrong?

Thanks!

Arthur

When you do string.format("%-15u", someNumber) you get a 15 character, left justified string, i.e.:

"0              "

"105            " etc.

When you go to try and align them right, you’re still aligning the spaces at the end.  I would either a) use “%15u” and not right align or “%u” and right align.  In either case you need to loose the minus sign.

Rob

Hi Rob,

Thanks again!  Nothing like another set of eyes!  I forgot I had the minus sign on for left justification.  I copied that code from another text field.

Regards,

Arthur

When you do string.format("%-15u", someNumber) you get a 15 character, left justified string, i.e.:

"0              "

"105            " etc.

When you go to try and align them right, you’re still aligning the spaces at the end.  I would either a) use “%15u” and not right align or “%u” and right align.  In either case you need to loose the minus sign.

Rob

Hi Rob,

Thanks again!  Nothing like another set of eyes!  I forgot I had the minus sign on for left justification.  I copied that code from another text field.

Regards,

Arthur