Numbers overlap when variables are changed

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

Good day mates,

I’m currently working on a little strategy game with planets and every planet has different values like food, population etc.
I have a building system where you can build housing which increases the population or farms to increase food. These values are displayed by labels and the numbers in the labels should change depending on the things you build.
The problem is that if I write it so that a starting value is assigned to each category and displayed in the labels and then the values change, the new value overlaps with the old one which is quite strange. That means that the new numbers are unreadable.

Pictures for reference:
With starting value displayed Nr.1

With starting value displayed Nr.2

Without starting value displayed Nr.1

Without starting value displayed Nr.2

And here is my code (with the starting value displayed):

extends Button

var PlanetPop = 1000
var PlanetFood = 100
var PlanetIndustry = 10
var PlanetTroops = 0

func _ready():

func _process(delta):
$PlanetOverview/Population/PopNumber.text = str(PlanetPop)

func _on_Planet_pressed():
$PlanetOverview.visible = !$PlanetOverview.visible

func _on_BuildHousing_pressed():

func buy_Housing_upgrade():
var CreditChange = get_node(“/root/InGame”)
if CreditChange.Credits >= 250 :
CreditChange.Credits -= 250
PlanetPop += 100
$PlanetOverview/Population/PopNumber.text = str(PlanetPop)

:bust_in_silhouette: Reply From: Dirque

I am not an expert in GDScript (or python) so I don’t know exactly what is going on but I am going to suggest that you write a blank string to the PopNumber.text first then the number you want.

That sadly didn’t work :frowning:
The numbers are still overlapping. The interesting thing though is that I can’t clear the label. The 1000 stays regardless of what I do.
But thanks for your help mate. I appreciate it :slight_smile:

Gamergo | 2019-11-18 11:07

Since all the formatting has been lost, is the last ‘$PlanetOverview/Population/PopNumber.text = str(PlanetPop)’ part of ‘func buyHousingupgrade():’? What happens when you write a 3rd number? Does it have all 3? Maybe you are inadvertently writing to different layers? I am just guessing.

Dirque | 2019-11-21 16:16