1
\$\begingroup\$

So, I want to code something in Godot, but the Label text doesn't get updated every frame. Here's the script I attached:

extends Node2D

onready var SportVar = $Label
var counter = 0

func _ready():
    pass 

func _process(delta):
    SportVar.text = (str(counter))
\$\endgroup\$
2
  • \$\begingroup\$ What did you do to debug and isolate the cause of the issue? \$\endgroup\$
    – Vaillancourt
    Oct 27, 2021 at 14:39
  • \$\begingroup\$ It would be updating every frame. Except it would be updating to exactly the same thing. Edit: assuming you want the counter to increment by one every frame, then liggiorgio gave you the correct solution. \$\endgroup\$
    – Theraot
    Oct 27, 2021 at 19:09

1 Answer 1

3
\$\begingroup\$

I'm assuming your script is attached to a parent Node2D node, and Label is a Label child node.

Your script is updating the content of the Label. The reason you don't see updates is that the content itself isn't changing.

Adding the following line to the _process() function will update the text:

func _process(delta):
    counter += 1    # Increase value before updating text
    SportVar.text = (str(counter))

This is a continuous text update. If you want to update on value changed only, you can use signals instead.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .