How to pass string+variable to text field

Godot Version



I’m new to programming AND new to godot, so forgive the very symple question.

Say i have a score variable, which gets regularly updated.

I want to regularly pass this variable to a label, so that the label always gets updated with the score and it shows something like:

Score: 100

Is there any way to update the label’s text field, telling it to set the label’s text to a string which would be:

Score: + “The value of the variable score converted to string”


I’m thinking of a function that does something like $Label.text = "Score: + score.toString" but I don’t know the correct syntax.

Sorry for the dumb question, i’ve only been programming for a few hours.

You can achieve this using gdscript’s format strings:

func update_score_label(score: int) -> void:
  $Label.text = "Score: %d" % score

Thank you!

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