So I am new to game development and I was trying to make a simple clicker game and my label wont update. This code is written in the script of the label I want to update. I could not find this on the forums so I thought I would ask.

extends Label

export var cash : int = 1

func _on_Button_button_down():
	cash += 1
	print(cash)

func _ready():
	self.text = "$ " + str(cash)

There may be something wrong with this code but I really don't know and it would be a great help if someone could help me solve this.

Thanks in advance!

  • _ready() doesn't update on every frame. Only when the node becomes ready after entering the SceneTree.

    You should do this:

    extends Label
    
    export var cash : int = 1
    
    func _on_Button_button_down():
    	cash += 1
    	self.text = "$ " + str(cash)
    	print(cash)
    
    func _ready():
    	self.text = "$ " + str(cash)

_ready() doesn't update on every frame. Only when the node becomes ready after entering the SceneTree.

You should do this:

extends Label

export var cash : int = 1

func _on_Button_button_down():
	cash += 1
	self.text = "$ " + str(cash)
	print(cash)

func _ready():
	self.text = "$ " + str(cash)