Menu
CoddyTech

Numbers into Text

Part of the Game Rules section of Coddy's Godot journey. Lesson 7 of 29.

A label's text is a string, and a score is a number. This line stops the game with an error:

$HUD/Score.text = "Coins left: " + left

GDScript does not add a number to a string. str() turns a value into text, then + joins the two strings:

str(3)		# "3"
"Lives: " + str(3)	# "Lives: 3"

Mind the quotes. str(left) is the number in the variable. "left" is the word left.

challenge icon

Challenge

Easy

Fix the error so the label shows Coins left: 3. Turn left into text with str().

Try it yourself

extends Node2D

func _ready():
	var left = get_tree().get_nodes_in_group("coins").size()
	$HUD/Score.text = "Coins left: " + left
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Game Rules

Practice on your own: Godot playground