Trying to display my players position

Godot Version

Godot 4.7.2.stable

Question

Im trying to have a label display my players x and y position but i dont know how i would implement that to my debug hud script?

extends CanvasLayer

@onready var PosLabel = $Control/Label

var player = get_tree().get_nodes_in_group("player")[0]

func _process(delta: float) -> void:
	PosLabel.text = "x: playerpos, y: playerpos"

PosLabel.text = "x: " + player.global_position.x + "y: " + player.global_position.y

Invalid operands ‘String’ and ‘float’ in operator ‘+’. ?

Can you show me your code now?

extends CanvasLayer

@onready var PosLabel = $Control/Label
@onready var player = get_tree().get_nodes_in_group("player")[0]

func _process(delta: float) -> void:
	PosLabel.text = "x: " + player.global_position.x + "y: " + player.global_position.y

right, I forgot, you need to use the str() function first.

"x: " + str(global_position.x) + " y: " + str(global_position.y)

you can convert using str() but I’d recommend using string formatters

func _process(delta: float) -> void:
	# using individual floats (with rounding to 2 decimals)
	PosLabel.text = "x: %.02f y: %.02f" % [player.global_position.x, player.global_position.y]
	# using vector formatter
	PosLabel.text = "%v" % player.global_position

thanks!

thanks