How have text fill Left to Right?

Hi there, I have been trying to figure out how to make it so when that the scores add up the numbers and score go right instead of left. Example

 --Example1: Score:1,000,000,000  
 --Example2: Score:1,000,000,000  
  

Like how example 1 is shown 1 mill is going left but in example 2 when you do it on device it goes off like example 2.

What is the proper code for how example 1 looks? [import]uid: 17058 topic_id: 24133 reply_id: 324133[/import]

have u looked at string.format(formatstring, e1, e2, …)

in http://lua-users.org/wiki/StringLibraryTutorial

ex: string.format("%6d", myNum)…

c [import]uid: 24 topic_id: 24133 reply_id: 97393[/import]

@anderoth do I put that in a function? [import]uid: 17058 topic_id: 24133 reply_id: 97407[/import]

Yep, you would make a function similar to what I posted. I usually have something like so. I have a variable for score, then a function to update it. Then just call the function with the new additional score value when I need to update it.

function updateScore(scr)  
-- ADD VALUE TO TOTAL SCORE  
 score = score + scr  
  
-- UPDATE SCORE TEXT WITH NEW TOTAL  
 scoreText.text = "Score: " .. tostring(score)  
  
-- RESET TEXT POSITION AND REF POINT  
 scoreText:setReferencePoint(CenterRightReferencePoint)  
 scoreText.x = 350  
 scoreText.y = 400  
end  
  
-- INITILIZE VARIABLES  
score = 0  
scoreText = display.newText("",0,0,native.systemFont,14)  
updateScore(0)  

In your code you just need to figure out the x and y position of where you want it to always be aligned. [import]uid: 56820 topic_id: 24133 reply_id: 97410[/import]

I may be confused by the question, but are you simply asking how to right justify the text?

If that is the case. You would use a right reference point for the text object. The key here is you need to reset the reference point and the x/y position after each text update.

For example. Below if you set the reference point to the right edge of the device’s screen, whenever you update the text, update the ref point and x/y again and it will always be right justified and will extend out towards the left as the text grows longer.

myText = display.newText("",0,0,native.systemFont,14)  
  
function updateText(newtext)  
 myText.text = newtext  
 myText:setReferencePoint(display.CenterRightReferencePoint)  
 myText.x = display.contentWidth  
 myText.y = display.contentHeight\*.5  
end  

The example would make the text act like so as you made it longer.

| |  
| T|  
| Te|  
| Tex|  
| Text|  

Hope that makes sense.

EDIT: fixed the code example. [import]uid: 56820 topic_id: 24133 reply_id: 97403[/import]