This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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 (75 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 (8,188 points)
selected by
0 votes

Alternatively, you can use format strings.

text = "%012d" % new_score
by (8,580 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 Frequently asked questions and 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 [email protected] with your username.