Creating a points UI

Godot Version

extends Label

@onready var apple_label = %apple_label

var apples_collected = 0

func _add_points():
apples_collected += 1 print (apples_collected)
` apple_label.text = "Apples Collected: " + str(apples_collected)

Question

I am trying to make a ui sort of thing on the top left of the screen that shows the player how much apples have been collected. However it does not work and the text just says "Apples Collected: ". I would appreciate any advice or recommendations.

Hi,
What’s the initial text in your Label node ? Isn’t "Apples Collected: " the default text ? If it is, maybe it means that you don’t call _add_points() method.
When you print apples_collected what does it print? If it doesn’t print anything, it means you really don’t go in the function.
You can also use string format like: apple_label.text = "Apples Collected: %s" % apples_collected → see (String format)

hi, the initial text of the node is named “AppleLabel” im new to godot and coding overall so im not sure what my next steps would be at this point in time.

No I meant what’s the text we entered in the text property of the Label node ?

ohh sorry the text is "Apples Collected: "

Ok sounds like nothing is calling your method _add_point(). Which object/part of your code calls this function?

im not sure, would changing point to apples_collected be the solution?

The first line in the code is:
extends Label

meaning that you’ve made a subclass for the Label class. You should not reference “apple_label” from within that class. Use the property right away, such as:
text = "My text"

Also, look in the debugger log. It’s very likely that you’ll have errors/warnings there that point you to these kind of structural issues.

im not sure what any of that means…