0 votes

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?

Godot version 3.2.3
in Engine by (73 points)

2 Answers

0 votes
Best answer
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

by (2,352 points)
selected by
0 votes

Alternatively, you can use format strings.

text = "%012d" % new_score
by (7,190 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.