How can i set the digits of the score?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By X

I’m making a arcade game in which foes gives 500 points to the player when them die.
The score is represented with a label with the following text = “000000000000” and when i add the new points to this score, all “0” disappear.

Here is the code:

func GetScore(New_Score):

 var NS = int($UI/Score.text) + New_Score
 $UI/Score.text = str(NS)

How can i fix that?

:bust_in_silhouette: Reply From: Inces
var NS = int(score.text) + new_score
var zeroes = 15 - str(NS).length()
score.text = ""
for x in range (zeroes):
     score.text += "0"
score.text += str(NS)

Number 15 is an example of how many numbers You want visible

:bust_in_silhouette: Reply From: exuin

Alternatively, you can use format strings.

text = "%012d" % new_score