String formatting?

I noticed that for the score, the text label is initially set to “SCORE: 9999”. However, I’m wondering why the score part is 9999 when the code does not format the in game score to four digits such as 0100, 0200 etc. Instead it’s displayed as SCORE: 100? It’s a minor point and when I first saw the “SCORE: 9999” I thought we were going to be shown how to format strings with leading zeros. So I read up on string formatting and found it’s very easy to do in GDScript using the lpad() command:

func set_score_label(new_score):
	score.text = "SCORE: " + str(new_score).lpad(4,"0")
2 Likes

i think it was just set to 9999 as a placeholder for aligning test text.

thats awesome tho, better than a long and confusing string.format and it does make it look nicer.

cheers for that share :+1:

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms